| Newsgroups |
php.bugs |
| Message-ID |
<[email protected]> |
Edit report at http://bugs.php.net/bug.php?id=50029&edit=1
ID: 50029
Comment by: [email protected]
Reported by: marc dot gray at gmail dot com
Summary: Weird invoke issue on class as property
Status: Analyzed
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: Ubuntu 9.04
PHP Version: 5.3.0
New Comment:
I can understand wanting to ensure that collisions between existing
methods and
invokable properties don't occur, but when there aren't any collisions,
it
doesn't make sense.
I'd argue that the following behavior should be implemented:
* If no matching method exists, simply allow invoking.
* If a matching method exists, call the method, and raise either an
E_NOTICE or
E_WARNING indicating the collision.
Right now, it's a fairly big WTF moment -- you expect it to work, and
instead
get an E_FATAL. Copying to a temporary variable is code clutter,
particularly
when you know the object is invokable.
Previous Comments:
------------------------------------------------------------------------
[2009-11-02 15:58:23] [email protected]
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();
------------------------------------------------------------------------
[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/bug.php?id=50029&edit=1