Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why are static variables not printed

Status
Not open for further replies.

Geates

Programmer
Aug 25, 2009
1,566
US
this:

Code:
class Test {
	public $A;
	public $B;
	public static $C;	
}

$test = new Test();

print_r($test);
var_dump($test);

yields:

Code:
Test Object ( [A] => [B] => )
object(Test)#1 (2) { ["A"]=> NULL ["B"]=> NULL }

Where is the static var C?

 
Its not displayed because it cannot be accessed non-statically.
A Static variable must be addressed statically, so the print_r and var_dump methods have no outside access to it through the instantiated object.

Try:

print_r($test::$C);

Some reading on static variables and how to access them:



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top