Bug #63789 [Opn]: Parse error on $this->otherInstance::method()
Edit report at https://bugs.php.net/bug.php?id=63789&edit=1
ID: 63789
Updated by: aharvey@php.net
Reported by: Alex at phpguide dot co dot il
Summary: Parse error on $this->otherInstance::method()
Status: Open
Type: Bug
-Package: Class/Object related
+Package: Scripting Engine problem
PHP Version: 5.4.9
Block user comment: N
Private report: N
New Comment:
Update the package â I'm pretty sure this is a limitation of the parser that isn't
likely to be fixed any time soon, but hopefully one of the guys who works on the parser can confirm
that.
Previous Comments:
------------------------------------------------------------------------
[2012-12-17 14:40:29] Alex at phpguide dot co dot il
Description:
------------
Calling a static method on an instance of class which is member of another class
results in parse error.
Test script:
---------------
class Speaker
{
public static function say($str) { echo $str; }
}
$speaker = new Speaker();
$speaker::say('This works');
class failingToCallSpeaker
{
private $speaker;
public function __construct(Speaker $s)
{
$this->speaker = $s;
}
public function doesntWork($str)
{
$this->speaker::say($str);
// PHP Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)
}
public function works($str)
{
$s = & $this->speaker;
$s::say($str);
}
}
$dontwork = new failingToCallSpeaker($speaker);
$dontwork->works('hurray');
$dontwork->doesntWork('argh');
Expected result:
----------------
PHP Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) on line
$this->speaker::say($str);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63789&edit=1
Thread (5 messages)