|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-06 02:00 UTC] thinice at gmail dot com
Description:
------------
When you try to access a static variable within a class using a variable variable to determine which class and static to use.
Reproduce code:
---------------
<?
class MyTest {
static $myVar = 'testval';
}
$sClass = 'MyTest';
echo "Expected output: ".MyTest::$myVar;
echo "<br/>";
$s = $sClass.'::$myVar';
echo "Using this as the string: ".$s."<br/>";
echo "Using Variable-named reference: ".${$s};
?>
Expected result:
----------------
Expected output: testval
Using this as the string: MyTest::$myVar
Using Variable-named reference: testval
Actual result:
--------------
Expected output: testval
Using this as the string: MyTest::$myVar
Using Variable-named reference:
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Fri Jan 09 21:00:02 2026 UTC |
As of PHP5.3 you can do class A { public static $foo = 2; } $a = new A; echo $a::$foo; // 2 $a used in a classname context will simply be converted to the class of the object. so it's equivalent to: $n = get_class($a); echo $n::$foo; // 2