Edit report at http://bugs.php.net/bug.php?id=51998&edit=1
ID: 51998 User updated by: php at paulisageek dot com Reported by: php at paulisageek dot com Summary: call_user_func_array can't use private methods on the $this pointer Status: Bogus Type: Bug Package: *General Issues Operating System: All PHP Version: 5.2.13 New Comment: But the originating request came from inside the object. With first class functions, you could just pass those around once you were inside the object (think python or javascipt). We should emulate the same in PHP. Previous Comments: ------------------------------------------------------------------------ [2010-06-05 10:32:40] degeb...@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. Of course you cannot call private instance methods outside of the object. That's the entire point of private methods. ------------------------------------------------------------------------ [2010-06-05 09:05:27] php at paulisageek dot com Description: ------------ I'd like to make a helper library that can use call_user_func outside of the object context, but still use private methods (obviously only when called from inside the object). Example attached: Test script: --------------- <?php class A { private function test1() { print 'side effect 1'; return false; } private function test2() { print 'side effect 2'; return 'yay'; } private function test3() { print 'side effect 3'; return 'nope'; } public function first() { return nonempty_lazy( array(array($this, 'test1')), array(array($this, 'test2')), array(array($this, 'test3'))); } } function nonempty_lazy() { $args = func_get_args(); foreach ($args as $arg) { $cb = array_shift($arg); $val = call_user_func_array($cb, $arg); if (!empty($val)) return $val; } } $a = new A; print $a->first(); Expected result: ---------------- side effect 1side effect 2yay Actual result: -------------- Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access private method A::test1() in /Users/ptarjan/tmp/cufa.php on line 28 Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access private method A::test2() in /Users/ptarjan/tmp/cufa.php on line 28 Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access private method A::test3() in /Users/ptarjan/tmp/cufa.php on line 28 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51998&edit=1