ID: 50029
Updated by: [email protected]
Reported By: marc dot gray at gmail dot com
-Status: Open
+Status: Analyzed
Bug Type: Class/Object related
Operating System: Ubuntu 9.04
PHP Version: 5.3.0
New Comment:
There was lots of discussion about this, because it could override
class methods like:
class Test {
private $closure;
public function __construct() {
$this->closure = function() {
echo 'Hello World';
};
}
public function closure() {
echo 'Hello PHP';
}
public function call() {
$this->closure();
}
}
$test = new Test;
// Call Test::$closure or Test::closure() now?
$test->call();
What you need to do is to copy the instance into a variable like:
$closoure = $this->closure;
$closure();
Previous Comments:
------------------------------------------------------------------------
[2009-10-29 01:15:36] marc dot gray at gmail dot com
Description:
------------
Placing a class with an __invoke method as a property inside another
class seems to nullify the invokeability of the original class.
Tested on:
Ubuntu 9.04, PHP 5.3.0
CentOS 5.3, PHP 5.2.11 ionCube / Suhosin
Reproduce code:
---------------
class a {
function __construct() { }
function __invoke() { echo("Invoked\n"); }
}
$a = new a();
$a();
// Prints: Invoked
class b {
private $x;
function __construct() {
$this->x = new a();
$this->x();
}
}
$b = new b();
// Issues error: undefined method b::x
Expected result:
----------------
I expect "new b()" construct to call the class a invoke
Actual result:
--------------
Undefined method - it doesn't seem to recognise the invokeable class
property as actually invokeable.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50029&edit=1