<[EMAIL PROTECTED]> wrote :

>>>> I guess I am going to have to write stupid code such as:
>>>> 
>>>> switch ($param1) {
>>>>     case 'parser1':
>>>>         return parser1::method();
>>>>     case 'parser2':
>>>>         return parser2::method();
>>>> }
>>> 
>>> call_user_func(array($param1, 'method'));
>> 
>> No. Undefined variable this in $param1. Get it ?
>> 
> No.  The code you displayed (in the switch block) is 100% identical to the
> code Derick offered (except for the fact that Derick's example will handle
> any class name while yours is limited).
> 
> $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'.

While,

Class MyObject {
    var $option;
    function MyObject($option) {
        $this->option = $option;
        call_user_func(array('foo', 'bar'));
    }
}

will return 'Undefined variable: this'...

This is why, if you need to access $this, you will choose to use ::
But because of the weird limitation that does not allow you to use it in a
dynamic way ( $var::method() ), you will need to use stupid switch like I
did above. Get it ?

> Get it?
> 
> -Pollita
> 
> P.S. - This thread has gone on long enough, either TRY IT, or take it to
> [EMAIL PROTECTED] where it belongs so that they can tell you the
> same thing.

Well, if you think that this thread is too long and that this is not a
problem or a limitation of PHP, good on you. You probably never had to deal
with such a case.

I just wanted to make sure there was really no other way than using the
stupid switch scenario.

Bertrand Mansion
Mamasam


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

Reply via email to