cvs: phpdoc /en/language/oop5 constants.xml paamayim-nekudotayim.xml static.xml

From: Date: Fri, 03 Aug 2007 09:59:57 +0000
Subject: cvs: phpdoc /en/language/oop5 constants.xml paamayim-nekudotayim.xml static.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969377225@lists.php.net to get a copy of this message
colder Fri Aug 3 09:59:57 2007 UTC Modified files: /phpdoc/en/language/oop5 constants.xml paamayim-nekudotayim.xml static.xml Log: Prepare documentation for dynamic static calls + fix erroneous information http://cvs.php.net/viewvc.cgi/phpdoc/en/language/oop5/constants.xml?r1=1.8&r2=1.9&diff_format=u Index: phpdoc/en/language/oop5/constants.xml diff -u phpdoc/en/language/oop5/constants.xml:1.8 phpdoc/en/language/oop5/constants.xml:1.9 --- phpdoc/en/language/oop5/constants.xml:1.8 Wed Jun 20 22:24:13 2007 +++ phpdoc/en/language/oop5/constants.xml Fri Aug 3 09:59:57 2007 @@ -1,20 +1,21 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <sect1 xml:id="language.oop5.constants" xmlns="http://docbook.org/ns/docbook"> <title>Class Constants</title> <para> 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 <varname>$</varname> symbol to declare or use them. Like - <link linkend="language.oop5.static">static</link> members, constant values - cannot be accessed from an instance of the object (using - <literal>$object::constant</literal>). + don't use the <varname>$</varname> symbol to declare or use them. </para> <para> The value must be a constant expression, not (for example) a variable, a class member, result of a mathematical operation or a function call. </para> + <para> + As of PHP 5.2.4, it's possible to reference the class using a variable. + </para> + <example> <title>Defining and using a constant</title> <programlisting role="php"> @@ -31,9 +32,13 @@ 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"; ?> ]]> </programlisting> http://cvs.php.net/viewvc.cgi/phpdoc/en/language/oop5/paamayim-nekudotayim.xml?r1=1.8&r2=1.9&diff_format=u Index: phpdoc/en/language/oop5/paamayim-nekudotayim.xml diff -u phpdoc/en/language/oop5/paamayim-nekudotayim.xml:1.8 phpdoc/en/language/oop5/paamayim-nekudotayim.xml:1.9 --- phpdoc/en/language/oop5/paamayim-nekudotayim.xml:1.8 Wed Jun 20 22:24:13 2007 +++ phpdoc/en/language/oop5/paamayim-nekudotayim.xml Fri Aug 3 09:59:57 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <sect1 xml:id="language.oop5.paamayim-nekudotayim" xmlns="http://docbook.org/ns/docbook"> <title>Scope Resolution Operator (::)</title> @@ -17,6 +17,10 @@ </para> <para> + As of PHP 5.2.4, it's possible to reference the class using a variable. + </para> + + <para> 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 @@ const CONST_VALUE = 'A constant value'; } +$classname = 'MyClass'; +echo $classname::CONST_VALUE; + echo MyClass::CONST_VALUE; ?> ]]> @@ -58,6 +65,9 @@ } } +$classname = 'OtherClass'; +echo $classname::doubleColon(); + OtherClass::doubleColon(); ?> ]]> http://cvs.php.net/viewvc.cgi/phpdoc/en/language/oop5/static.xml?r1=1.11&r2=1.12&diff_format=u Index: phpdoc/en/language/oop5/static.xml diff -u phpdoc/en/language/oop5/static.xml:1.11 phpdoc/en/language/oop5/static.xml:1.12 --- phpdoc/en/language/oop5/static.xml:1.11 Fri Jul 27 09:02:38 2007 +++ phpdoc/en/language/oop5/static.xml Fri Aug 3 09:59:57 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.11 $ --> +<!-- $Revision: 1.12 $ --> <sect1 xml:id="language.oop5.static" xmlns="http://docbook.org/ns/docbook"> <title>Static Keyword</title> @@ -24,15 +24,6 @@ </para> <para> - In fact <literal>static</literal> 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 - <literal>self</literal> then <literal>self</literal> is translated to - the current class, that is the class the code belongs to. Here also no - inheritance rules apply. - </para> - - <para> Static properties cannot be accessed through the object using the arrow operator -&gt;. </para> @@ -41,6 +32,10 @@ Calling non-static methods statically generates an E_STRICT level warning. </para> + <para> + As of PHP 5.2.4, it's possible to reference the class using a variable. + </para> + <example> <title>Static member example</title> <programlisting role="php"> @@ -74,6 +69,9 @@ print Bar::$my_static . "\n"; $bar = new Bar(); print $bar->fooStatic() . "\n"; + +$classname = "Bar"; +print $classname::$my_static; ?> ]]> </programlisting> @@ -91,6 +89,9 @@ } Foo::aStaticMethod(); + +$classname = "Foo"; +print $classname::aStaticMethod(); ?> ]]> </programlisting>

« previous php.doc (#969377225) next »