Edit report at https://bugs.php.net/bug.php?id=63482&edit=1
ID: 63482
Comment by: dev at pp3345 dot de
Reported by: dev at pp3345 dot de
Summary: register_tick_function() does not work correctly
with private methods
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Debian Squeeze
PHP Version: 5.4.8
Block user comment: N
Private report: N
New Comment:
I understand that private methods can not be called from outside the class. But
I
believe that register_tick_function() should disallow registering private or
protected methods or at least there should only be ONE error after leaving the
class scope. Probably PHP should automatically recognize that the class scope
was
left, unregister the tick function and issue a notice.
As far as I remember, private methods are fully supported as class autoloaders
and
work even when loading a class outside the class scope of the registered
private
method. This behavior is somewhat inconsistent.
Previous Comments:
------------------------------------------------------------------------
[2012-11-10 20:42:45] [email protected]
As the tick function is not called in the class scope it also can't access its
private methods. That's the whole point of private methods. This is also not
specific to ticks, its the same with all private-method callbacks: They will
only work if they are invoked from within the class.
------------------------------------------------------------------------
[2012-11-10 19:12:40] dev at pp3345 dot de
Description:
------------
Registering a private method as a tick function leads to two errors on every
tick.
Test script:
---------------
<?php
declare(ticks = 1);
class A {
public function __construct() {
register_tick_function(array($this, 'a'));
}
private function a() {
echo 'Called';
}
}
new A;
?>
Expected result:
----------------
CalledCalledCalled
Actual result:
--------------
Called
Warning: Invalid callback A::a, cannot access private method A::a() in
/var/vhosts/pancake/default/register_tick_function.php on line 15
Warning: main(): Unable to call A::a() - function does not exist in
/var/vhosts/pancake/default/register_tick_function.php on line 15
Warning: Invalid callback A::a, cannot access private method A::a() in
/var/vhosts/pancake/default/register_tick_function.php on line 17
Warning: main(): Unable to call A::a() - function does not exist in
/var/vhosts/pancake/default/register_tick_function.php on line 17
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63482&edit=1