>> but this should not be the only way. What I mean is:
>>
>> static public function put($key, $value) {
>>      $me = self::getInstance();
>>      $me[$key] = $value;
>> }
>
> That sounds fine to me.  As long as it's not called register() and
> registry()!
>
> I have updated the proposal page.  But it has to work statically and
> dynamically, so I made $me set either to $this or self::getInstance().

if (isset($this)) {
    $instance = $this;
} else {
    $instance = self::getInstance();
}

Which would be great, but it doesn't work.

class Registry
{
    function get()
    {
        if (isset($this)) {
            print '$this is defined (' . get_class($this) . ')<br />';
        } else {
            print '$this is not defined<br />';
        }
    }
}

class IndexController
{
    function indexAction()
    {
        Registry::get();
        $registry = new Registry();
        $registry->get();
    }
}

$index = new IndexController();
$index->indexAction();

// Outputs:

$this is defined (IndexController)
$this is defined (Registry)

You could check the class name in Registry, but either way it's going to
give you an E_STRICT error.  Methods cannot be called in both static and
object contexts in PHP if they refer to $this at any time.

-Matt

Reply via email to