|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-06-05 10:32 UTC] degeberg@php.net
-Status: Open
+Status: Bogus
[2010-06-05 10:32 UTC] degeberg@php.net
[2010-06-05 10:38 UTC] php at paulisageek dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 20:00:01 2025 UTC |
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