Index: en/language/oop5/constants.xml =================================================================== RCS file: /repository/phpdoc/en/language/oop5/constants.xml,v retrieving revision 1.8 diff -u -p -r1.8 constants.xml --- en/language/oop5/constants.xml 20 Jun 2007 22:24:13 -0000 1.8 +++ en/language/oop5/constants.xml 3 Aug 2007 09:54:15 -0000 @@ -5,16 +5,17 @@ It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you - don't use the $ symbol to declare or use them. Like - static members, constant values - cannot be accessed from an instance of the object (using - $object::constant). + don't use the $ symbol to declare or use them. The value must be a constant expression, not (for example) a variable, a class member, result of a mathematical operation or a function call. + + As of PHP 5.2.4, it's possible to reference the class using a variable. + + Defining and using a constant @@ -31,9 +32,13 @@ class MyClass echo MyClass::constant . "\n"; +$classname = "MyClass"; +echo $classname::constant . "\n"; + $class = new MyClass(); $class->showConstant(); -// echo $class::constant; is not allowed + +echo $class::constant."\n"; ?> ]]> Index: en/language/oop5/paamayim-nekudotayim.xml =================================================================== RCS file: /repository/phpdoc/en/language/oop5/paamayim-nekudotayim.xml,v retrieving revision 1.8 diff -u -p -r1.8 paamayim-nekudotayim.xml --- en/language/oop5/paamayim-nekudotayim.xml 20 Jun 2007 22:24:13 -0000 1.8 +++ en/language/oop5/paamayim-nekudotayim.xml 3 Aug 2007 09:54:15 -0000 @@ -17,6 +17,10 @@ + As of PHP 5.2.4, it's possible to reference the class using a variable. + + + Paamayim Nekudotayim would, at first, seem like a strange choice for naming a double-colon. However, while writing the Zend Engine 0.5 (which powers PHP 3), that's what the Zend team decided to call it. @@ -32,6 +36,9 @@ class MyClass { const CONST_VALUE = 'A constant value'; } +$classname = 'MyClass'; +echo $classname::CONST_VALUE; + echo MyClass::CONST_VALUE; ?> ]]> @@ -58,6 +65,9 @@ class OtherClass extends MyClass } } +$classname = 'OtherClass'; +echo $classname::doubleColon(); + OtherClass::doubleColon(); ?> ]]> Index: en/language/oop5/static.xml =================================================================== RCS file: /repository/phpdoc/en/language/oop5/static.xml,v retrieving revision 1.11 diff -u -p -r1.11 static.xml --- en/language/oop5/static.xml 27 Jul 2007 09:02:38 -0000 1.11 +++ en/language/oop5/static.xml 3 Aug 2007 09:54:15 -0000 @@ -24,15 +24,6 @@ - In fact static method calls are resolved at compile - time. When using an explicit class name the method is already identified - completely and no inheritance rules apply. If the call is done by - self then self is translated to - the current class, that is the class the code belongs to. Here also no - inheritance rules apply. - - - Static properties cannot be accessed through the object using the arrow operator ->. @@ -41,6 +32,10 @@ Calling non-static methods statically generates an E_STRICT level warning. + + As of PHP 5.2.4, it's possible to reference the class using a variable. + + Static member example @@ -74,6 +69,9 @@ print $foo->my_static . "\n"; // Un print Bar::$my_static . "\n"; $bar = new Bar(); print $bar->fooStatic() . "\n"; + +$classname = "Bar"; +print $classname::$my_static; ?> ]]> @@ -91,6 +89,9 @@ class Foo { } Foo::aStaticMethod(); + +$classname = "Foo"; +print $classname::aStaticMethod(); ?> ]]>