Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343356

Summary: Calling a static variable using a variable variable to reference a class causes an error to appear in the problems tray.
Product: z_Archived Reporter: shadowadler
Component: PDTAssignee: PHP Debug <php.debug-inbox>
Status: CLOSED WORKSFORME QA Contact: Ilina Stefanova <ilina.s>
Severity: normal    
Priority: P3 CC: euthanasia_waltz, ganoro, kalin.a, pligor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description shadowadler CLA 2011-04-20 05:16:01 EDT
Build Identifier: M20100211-1343

When a variable variable is used to describe a class name in order to call a static method, the validator picks this out as an error (because, I think, it understands that I am trying to call a static method from a variable, which is wrong, but not actually what I am doing).

The code works when run, and triggers no errors from php 5.3.

Reproducible: Always

Steps to Reproduce:
Code to reproduce error:

class myClass {
	static $greeting = "hello\n";
	
	public function greet() {
		$thisClass = __CLASS__;
		return $thisClass::$greeting;//error will 'occur' here.
	}
}

class myChild extends myClass {
	
	public function greet() {
		$thisClass = __CLASS__;
		return $thisClass::$greeting;//error will 'occur' here.
	}
}
//should print_>  hello hello when summoned as webpage.

$me = new myClass;
$child = new myChild;

echo $me->greet();
echo $child->greet();
Comment 1 Toshihiro Izumi CLA 2011-05-04 23:41:48 EDT
This had been solved on Helios(eclipse 3.6.0, pdt 2.2.0) long ago.
Comment 2 Roy Ganor CLA 2011-05-05 13:34:09 EDT
closing per Toshihiro Izumi comment.

Toshihiro - can I contact you by email somehow?
Comment 3 George Pligor CLA 2011-06-19 07:43:39 EDT
NO it is not resolved as it is mentioned in here
I just download Eclipse SDK for PHP developers and I have the same situation. Let's say you have declared a class named Employer then this code:

$myclass = "Employer";
$myclass::GoThere();

will produce an error inside the editor. Although if you execute it using php no warning or error occurs because it is correct.

Could you please fix it as soon as possible? Or provide a workaround if that is possible...

Thank you!
George Pligor
Comment 4 Toshihiro Izumi CLA 2011-06-19 09:07:43 EDT
Hi George,
I cannot reproduce your problem.
Do you mean "syntax error, unexpected '::'" as "an error inside the editor" ?
That error is correct unless you set "PHP 5.3" as PHP Version(Preferences>PHP>PHP Interpreter, or project properties).
Could you make sure PHP Version?
Comment 5 George Pligor CLA 2011-06-19 10:26:37 EDT
Ok! Yes this fixed it.. I wouldn't guess that eclipse would implement multiple interpreters since php is easily upgradable and everyone uses the latest version. I guess there could be some rare occasions where an old php version is required (such as facebook engineering puzzles)
Thank you! you saved the day (:
Comment 6 Kalin CLA 2011-07-27 08:53:11 EDT
No longer reproducible.
Closing...