#50029 [Opn->Ana]: Weird invoke issue on class as property

From: Date: Mon, 02 Nov 2009 15:58:23 +0000
Subject: #50029 [Opn->Ana]: Weird invoke issue on class as property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-144169@lists.php.net to get a copy of this message
ID: 50029 Updated by: kalle@php.net 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

« previous php.bugs (#144169) next »