#45728 [Fbk->Opn]: Static references via Variable Variables

[email protected] ("thinice at gmail dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
 ID:               45728
 User updated by:  thinice at gmail dot com
 Reported By:      thinice at gmail dot com
-Status:           Feedback
+Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: FreeBSD
 PHP Version:      5.2.6
 New Comment:

You can access non-statics this way.

$myClass = 'MyClass';
echo $myClass->anythingElse;

Why wouldn't you be able to access variables via :: ?

I don't see anything on whether this should, or should not work. But
why shouldn't/wouldn't it be possible to access a static variable using
a variable to set the object name?


Previous Comments:
------------------------------------------------------------------------

[2008-08-07 09:53:09] [email protected]

Where exactly it says this should work..?

------------------------------------------------------------------------

[2008-08-06 02:00:46] 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:


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45728&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.