Mike,

yes i know the difference. I actually discovered that by accident when i've forgot to write the static keyword. my code lead to an exception. i wondered about the details of that exception and came to the solution that the behavior as decribed exists. in my opinion one could really use that behavior for a design pattern in order to dynamically add abilities to objects. (e.g. implement __call interceptor and statically call the method of another "ability provider"-class statically. it would behave just like a native function of that object.)


Am 22.05.2011 16:47, schrieb Mike Mackintosh:
Simon,

You may want to be careful with the way you declare your class methods.

Example:

public function bar() != static function bar(), even if you use 
pnysudsfksdljfasdjfsd (::)

See the example below.

class Foo{

static function barStatic()
        {
        echo get_class($this);
        }
public function barPublic()
        {
        echo get_class($this);
        }

}

class Foobar{

public function callBarStatic()
        {
        Foo::barStatic();
        }
public function callBarPublic()
        {
        Foo::barPublic();
        }

}

$oo = new Foobar;
$oo->callBarStatic(); // returns only Foo
$oo->callBarPublic(); // returns Foobar





On May 22, 2011, at 10:17 AM, Simon Hilz wrote:

hi,

lets assume the following classes:

class Foo{

public function bar()
        {
        echo get_class($this);
        }

}

class Foobar{

public function callBarStatic()
        {
        Foo::bar();
        }

}

the following code results in the output "Foobar":

$obj = new Foobar();
$obj->callBarStatic();

That means that the static call of bar() is executed in the context of Foobar. 
Is this behavior deliberate? If so, it would open a great way of object 
composition patterns. But only if it will be retained in future versions :) 
(i've tested with 5.3.5)


Simon Hilz

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to