From:
Operating system: All
PHP version: 5.2.13
Package: *General Issues
Bug Type: Bug
Bug description:call_user_func_array can't use private methods on the $this
pointer
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 bug report at http://bugs.php.net/bug.php?id=51998&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51998&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51998&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=51998&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=51998&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51998&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51998&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51998&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51998&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51998&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51998&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51998&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51998&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51998&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51998&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51998&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51998&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51998&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51998&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51998&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51998&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51998&r=mysqlcfg