Bug->Req #63789 [Opn]: Parse error on $this->otherInstance::method()

From: Date: Tue, 18 Dec 2012 02:49:35 +0000
Subject: Bug->Req #63789 [Opn]: Parse error on $this->otherInstance::method()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-175421@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63789&edit=1

 ID:                 63789
 Updated by:         laruence@php.net
 Reported by:        Alex at phpguide dot co dot il
 Summary:            Parse error on $this->otherInstance::method()
 Status:             Open
-Type:               Bug
+Type:               Feature/Change Request
 Package:            Scripting Engine problem
 PHP Version:        5.4.9
-Assigned To:        
+Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

you don't need always use :: to call static method,  actually,  :: doesn't means 
calling static method all the time.

you could use $this->speaker->say($str).

anyway, I agree we can do some improvement here, assign to myself. I can solve 
this in the mean time of implement the instance function call FR

thanks


Previous Comments:
------------------------------------------------------------------------
[2012-12-18 00:35:31] aharvey@php.net

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.

------------------------------------------------------------------------
[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)

« previous php.bugs (#175421) next »