|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-30 15:22 UTC] tony2001@php.net
[2005-09-30 15:41 UTC] claudio dot frizziero at nereal dot com
[2005-09-30 15:46 UTC] tony2001@php.net
[2005-09-30 16:28 UTC] claudio dot frizziero at nereal dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 21:00:01 2025 UTC |
Description: ------------ When I use call_user_func (and call_user_func_array, of course) inside a method to call a method of another class I'm expecting it works like the scope resolution operator. If it is not a bug: is it possible to add a flag, or alternatively add two similar function (i.e. call_user_func_Paamayim_Nekudotayim and call_user_func_array_Paamayim_Nekudotayim 8), to avoid the eval workaround? Thank you! Note: i'm using php 5.0.4, but I don't find any fix in the changelog to 5.0.5 Reproduce code: --------------- class MyClass { public $string = 'Hello!'; public function SayHello() { call_user_func(array('OutputClass', 'WriteToOutput')); // } public function SayHello2() { OutputClass::WriteToOutput(); } public function SayHello3($outputclass, $outputmethod) { // $outputclass::$outputmethod(); // syntax not allowed, with or without curly braces eval($outputclass . '::' . $outputmethod . '();'); // it works, but it's a workaround } } class OutputClass { public function WriteToOutput() { echo ($this->string); } } $a = new MyClass(); $a->SayHello(); // Fatal error: Using $this when not in object context $a->SayHello2(); // it works (wow!) $a->SayHello3('OutputClass', 'WriteToOutput'); // it works only using eval