ID:               45728
 Updated by:       [EMAIL PROTECTED]
 Reported By:      thinice at gmail dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Scripting Engine problem
 Operating System: FreeBSD
 PHP Version:      5.2.6
 New Comment:

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


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

[2008-08-07 15:07:56] thinice at gmail dot com

All I can see in documentation is that you can't use :: for accessing
the static from an instantiated object.

e.g.: Documentation explicitly says this will -not- work:
$myClass = new MyClass;
echo $myClass::myVar;

But this isn't the problem.

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

[2008-08-07 15:01:59] thinice at gmail dot com

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?

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

[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

Reply via email to