--- Bertrand Mansion <[EMAIL PROTECTED]> wrote: > <[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'.
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? > > 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 __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php