<[EMAIL PROTECTED]> wrote :

> 
> --- Bertrand Mansion <[EMAIL PROTECTED]> wrote:
>> <[EMAIL PROTECTED]> wrote?:
>> 
>>> $classname::method() === call_user_func(array($classname,'method'));
>> 
>> No. $classname::method() is illegal and is in no case === to
>> call_user_func(array($classname,'method')) as you state it.
>> 
>> Class foo {
>>     function bar() {
>>         echo $this->param;
>>     }
>> }
>> 
>> Class MyObject {
>>     var $param;
>>     function MyObject($param) {
>>         $this->param = $param;
>>         foo::bar();
>>     }
>> }
>> 
>> $obj = new MyObject('out of this');
>> 
>> will print 'from MyObject'.
> 
> 
> This SHOULDN'T print 'out of this', This seems like a bug, and you SHOULDN'T
> depend on this functionality. The scope of $this inside class foo method bar,
> Should be to foo::bar NOT MyObject::MyObject. Which if my memory serves me
> right $this inside a static method will just be the string of the current
> class?

Hi Brad,

Are you sure about that ? The manual states that this is the normal
behaviour which I find very handy and useful in many cases. I see a lot of
possibilities with this feature, for instance a way to develop some kind of
plug-ins for existing classes without having to extend them.

This can probably lead to some dangerous code but this goes far beyond my
knowledge.

Anyway, if someone aware could give some clarifications on should I rely or
not on this behaviour, that would be very appreciated.

If this behaviour could be extended to support $className::method(), that
would be just great.

>> 
>> While,
>> 
>> Class MyObject {
>>     var $option;
>>     function MyObject($option) {
>>         $this->option = $option;
>>         call_user_func(array('foo', 'bar'));
>>     }
>> }
>> 
>> will return 'Undefined variable: this'...
> 
> This should be the way that both examples function.
> 
> $this is a refrence to the current object. inside a static method like
> foo::bar() there is no $this defined because its static.
> 
> 
> - Brad


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to