cvs: phpdoc-fr /language oop5.xml /language/context http.xml /language/oop5 interfaces.xml overloading.xml reflection.xml static.xml
| From: | Guillaume Plessis | Date: | Wed, 03 Dec 2008 23:09:25 +0000 |
| Subject: | cvs: phpdoc-fr /language oop5.xml /language/context http.xml /language/oop5 interfaces.xml overloading.xml reflection.xml static.xml | ||
| Groups: | php.doc.fr | ||
| Request: | Send a blank email to doc-fr+get-6141@lists.php.net to get a copy of this message | ||
gui Wed Dec 3 23:09:25 2008 UTC
Modified files:
/phpdoc-fr/language oop5.xml
/phpdoc-fr/language/context http.xml
/phpdoc-fr/language/oop5 interfaces.xml overloading.xml
reflection.xml static.xml
Log:
sync with EN, time to sleep
http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5.xml?r1=1.18&r2=1.19&diff_format=u Index: phpdoc-fr/language/oop5.xml diff -u phpdoc-fr/language/oop5.xml:1.18 phpdoc-fr/language/oop5.xml:1.19 --- phpdoc-fr/language/oop5.xml:1.18 Mon Dec 1 16:24:37 2008 +++ phpdoc-fr/language/oop5.xml Wed Dec 3 23:09:25 2008 @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.18 $ --> -<!-- EN-Revision: 1.15 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.19 $ --> +<!-- EN-Revision: 1.16 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <chapter xml:id="language.oop5" xmlns="http://docbook.org/ns/docbook"> <title>Les classes et les objets (PHP 5)</title> - <sect1 xml:id="op5.intro"> + <sect1 xml:id="oop5.intro"> <title>Introduction</title> <para> En PHP 5, il y a un tout nouveau modèle objet. La gestion des objets en PHP http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/context/http.xml?r1=1.6&r2=1.7&diff_format=u Index: phpdoc-fr/language/context/http.xml diff -u phpdoc-fr/language/context/http.xml:1.6 phpdoc-fr/language/context/http.xml:1.7 --- phpdoc-fr/language/context/http.xml:1.6 Thu Aug 21 23:01:26 2008 +++ phpdoc-fr/language/context/http.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> -<!-- EN-Revision: 1.4 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.7 $ --> +<!-- EN-Revision: 1.5 Maintainer: yannick Status: ready --> <!-- Reviewed: no --> <refentry xml:id="context.http" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" role="noversion"> @@ -204,6 +204,8 @@ Ajout la possibilité d'utiliser des proxy HTTPS via des proxy HTTP. </entry> + </row> + <row> <entry>5.1.0</entry> <entry> Ajout du paramètre <parameter>max_redirects</parameter>. http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/interfaces.xml?r1=1.12&r2=1.13&diff_format=u Index: phpdoc-fr/language/oop5/interfaces.xml diff -u phpdoc-fr/language/oop5/interfaces.xml:1.12 phpdoc-fr/language/oop5/interfaces.xml:1.13 --- phpdoc-fr/language/oop5/interfaces.xml:1.12 Sun Jul 22 17:16:11 2007 +++ phpdoc-fr/language/oop5/interfaces.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.12 $ --> -<!-- EN-Revision: 1.10 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.13 $ --> +<!-- EN-Revision: 1.14 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <sect1 xml:id="language.oop5.interfaces" xmlns="http://docbook.org/ns/docbook"> @@ -30,6 +30,19 @@ fonctions, puisque cela causerait une ambiguïté. </para> </note> + <note> + <para> + Les interfaces peuvent être étendues comme des classes en utilisant l'opérateur <literal>extend</literal>. + </para> + </note> + </sect2> + <sect2 xml:id="language.oop5.interfaces.constants"> + <title><literal>Les constantes</literal></title> + <para> + Les interfaces peuvent contenir des constantes. Les constantes d'interfaces fonctionnent exactement + comme les <link linkend="language.oop5.constants">constantes de classe</link>. Elles ne peuvent pas + être écrasées par des classes ou des interfaces qui en héritent. + </para> </sect2> <sect2 xml:id="language.oop5.interfaces.examples"> &reftitle.examples; @@ -38,6 +51,7 @@ <programlisting role="php"> <![CDATA[ <?php + // Declaration de l'interface 'iTemplate' interface iTemplate { @@ -82,12 +96,118 @@ ]]> </programlisting> </example> + <example xml:id="language.oop5.interfaces.examples.ex2"> + <title>Les interfaces extensibles</title> + <programlisting role="php"> +<![CDATA[ +<?php +interface a +{ + public function foo(); +} + +interface b extends a +{ + public function baz(Baz $baz); +} + +// Ceci ne fonctionnera pas +class c implements b +{ + public function foo() + { + } + + public function baz(Baz $baz) + { + } +} + +// Ceci ne fonctionnera pas et soulèvera une erreur fatale +class d implements b +{ + public function foo() + { + } + + public function baz(Foo $foo) + { + } +} +?> +]]> + </programlisting> + </example> + <example xml:id="language.oop5.interfaces.examples.ex3"> + <title>L'héritage de plusieurs interfaces</title> + <programlisting role="php"> +<![CDATA[ +<?php +interface a +{ + public function foo(); +} + +interface b +{ + public function bar(); +} + +interface c extends a, b +{ + public function baz(); +} + +class d implements c +{ + public function foo() + { + } + + public function bar() + { + } + + public function baz() + { + } +} +?> +]]> + </programlisting> + </example> + <example xml:id="language.oop5.interfaces.examples.ex4"> + <title>Les interfaces avec des constantes</title> + <programlisting role="php"> +<![CDATA[ +<?php +interface a +{ + const b = 'Constante de l\'interface'; +} + +// Affiche: Constante de l'interface +echo a::b; + + +// Ceci ne fonctionnera pas de toutes façons vu qu'il n'est pas autorisé +// d'écraser des constantes. C'est le même principe qu'avec les constantes +// de classe +class b implements a +{ + const b = 'Constante de classe'; +} +?> +]]> + </programlisting> + </example> <simpara> Voir aussi l'opérateur <link linkend="language.operators.type">instanceof</link>. </simpara> </sect2> -</sect1> + + </sect1> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/overloading.xml?r1=1.28&r2=1.29&diff_format=u Index: phpdoc-fr/language/oop5/overloading.xml diff -u phpdoc-fr/language/oop5/overloading.xml:1.28 phpdoc-fr/language/oop5/overloading.xml:1.29 --- phpdoc-fr/language/oop5/overloading.xml:1.28 Sun Jun 8 07:02:08 2008 +++ phpdoc-fr/language/oop5/overloading.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.28 $ --> -<!-- EN-Revision: 1.30 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.29 $ --> +<!-- EN-Revision: 1.32 Maintainer: yannick Status: ready --> <!-- Reviewed: no --> <sect1 xml:id="language.oop5.overloading" xmlns="http://docbook.org/ns/docbook"> @@ -69,6 +69,7 @@ <entry>5.3.0</entry> <entry> Ajout de <literal>__callStatic()</literal>. + Ajout d'un avertissement pour forcer la visibilité <literal>public</literal> et la déclaration non <literal>static</literal>. </entry> </row> </tbody> @@ -145,7 +146,7 @@ /** La surcharge n'est pas utilisée sur les membres déclarés. */ public $declared = 1; - /** La surcharge n'est pas lancée lorsque l'on accède à la classe. */ + /** La surcharge n'est lancée que lorsque l'on accède à la classe depuis l'extérieur. */ private $hidden = 2; public function __set($name, $value) { @@ -161,7 +162,7 @@ $trace = debug_backtrace(); trigger_error( - 'Propriété non-définie : ' . $name . + 'Propriété non-définie via __get(): ' . $name . ' dans ' . $trace[0]['file'] . ' à la ligne ' . $trace[0]['line'], E_USER_NOTICE); @@ -182,7 +183,6 @@ /** Ce n'est pas une méthode magique, nécessaire ici que pour l'exemple. */ public function getHidden() { - echo "'hidden' visible ici, donc __get() non utilisé\n"; return $this->hidden; } } @@ -193,14 +193,19 @@ $obj = new MemberTest; $obj->a = 1; -echo $obj->a . "\n"; +echo $obj->a . "\n\n"; var_dump(isset($obj->a)); unset($obj->a); var_dump(isset($obj->a)); +echo "\n"; -echo $obj->declared . "\n"; +echo $obj->declared . "\n\n"; + +echo "Manipulons maintenant la propriété privée nommée 'hidden':\n"; +echo "'hidden' est visible depuis la classe, donc __get() n'est pas utilisé...\n"; echo $obj->getHidden() . "\n"; +echo "'hidden' n'est pas visible en dehors de la classe, donc __get() est utlisé...\n"; echo $obj->hidden . "\n"; ?> ]]> @@ -211,18 +216,23 @@ Définition de 'a' à '1' Récupération de 'a' 1 + Est-ce que 'a' est défini ? bool(true) Effacement de 'a' Est-ce que 'a' est défini ? bool(false) + 1 -'hidden' visible ici, donc __get() non utilisé + +Manipulons maintenant la propriété privée nommée 'hidden': +'hidden' est visible depuis la classe, donc __get() n'est pas utilisé... 2 +'hidden' n'est pas visible en dehors de la classe, donc __get() est utlisé... Récupération de 'hidden' -Notice: Propriété non-définie : hidden dans <file> à la ligne 64 dans <file> à la ligne 28 +Notice: Propriété non-définie via __get(): hidden dans <file> à la ligne 64 dans <file> à la ligne 28 ]]> </screen> http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/reflection.xml?r1=1.33&r2=1.34&diff_format=u Index: phpdoc-fr/language/oop5/reflection.xml diff -u phpdoc-fr/language/oop5/reflection.xml:1.33 phpdoc-fr/language/oop5/reflection.xml:1.34 --- phpdoc-fr/language/oop5/reflection.xml:1.33 Sun Jun 8 18:44:27 2008 +++ phpdoc-fr/language/oop5/reflection.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.33 $ --> -<!-- EN-Revision: 1.35 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.34 $ --> +<!-- EN-Revision: 1.39 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <sect1 xml:id="language.oop5.reflection" xmlns="http://docbook.org/ns/docbook"> @@ -34,8 +34,7 @@ L'API de réflexion est une extension orientée objet du Moteur Zend, constituée des classes suivantes : </para> - <example> - <title>API de réflexion</title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php @@ -52,7 +51,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <simpara> Pour plus de détails sur ces classes, lisez les chapitres suivants. @@ -96,7 +95,6 @@ Method [ <internal> final private method __clone ] { } - Method [ <internal, ctor> public method __construct ] { - Parameters [2] { @@ -170,8 +168,7 @@ La classe <classname>ReflectionFunction</classname> vous permet de faire du <literal>reverse-engineering</literal> sur les fonctions. </para> - <example> - <title>La classe <classname>ReflectionFunction</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php @@ -184,6 +181,7 @@ public string getName() public bool isInternal() public bool isDisabled() + public mixed getClosure() /* Depuis PHP 5.3.0 */ public bool isUserDefined() public string getFileName() public int getStartLine() @@ -200,7 +198,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <para> La classe parent <classname>ReflectionFunctionAbstract</classname> a les mêmes méthodes, exceptée <function>invoke</function>, <function>invokeArgs</function>, @@ -231,7 +229,6 @@ function counter() { static $c = 0; - return $c++; } @@ -286,15 +283,14 @@ La classe <classname>ReflectionParameter</classname> récupère les informations concernant les paramètres des fonctions ou des méthodes. </para> - <example> - <title>La classe <classname>ReflectionParameter</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionParameter implements Reflector { final private __clone() - public object __construct(string function, string parameter) + public void __construct(string function, string parameter) public string __toString() public static string export(mixed function, mixed parameter, bool return) public string getName() @@ -312,7 +308,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <para> <function>getDefaultValue</function>, @@ -375,15 +371,14 @@ de faire du <literal>reverse-engineering</literal> sur des classes et des interfaces. </para> - <example> - <title>La classe <classname>ReflectionClass</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionClass implements Reflector { final private __clone() - public object __construct(string name) + public void __construct(string name) public string __toString() public static string export(mixed class, bool return) public string getName() @@ -426,7 +421,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <simpara> <function>hasConstant</function>, <function>hasMethod</function>, @@ -458,7 +453,6 @@ /** * Une classe compteur - * */ class Compteur extends Object implements Linearisable { @@ -471,8 +465,7 @@ * @access public * @return int */ - public function count() - { + public function count() { return self::$c++; } } @@ -558,7 +551,7 @@ class ReflectionObject extends ReflectionClass { final private __clone() - public object __construct(mixed object) + public void __construct(mixed object) public string __toString() public static string export(mixed object, bool return) } @@ -574,14 +567,13 @@ La classe <classname>ReflectionMethod</classname> vous permet de faire du <literal>reverse-engineering</literal> sur les méthodes des classes. </para> - <example> - <title>La classe <classname>ReflectionMethod</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionMethod extends ReflectionFunctionAbstract implements Reflector { - public __construct(mixed class, string name) + public void __construct(mixed class, string name) public string __toString() public static string export(mixed class, string name, bool return) public mixed invoke(stdclass object [, mixed args [, ...]]) @@ -595,6 +587,7 @@ public bool isConstructor() public bool isDestructor() public int getModifiers() + public mixed getClosure() /* Depuis PHP 5.3.0 */ public ReflectionClass getDeclaringClass() // Inherited from ReflectionFunctionAbstract @@ -615,7 +608,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <para> Pour connaître le fonctionnement d'une méthode, vous devez d'abord créer une instance de la classe <classname>ReflectionMethod</classname>. Vous @@ -686,6 +679,27 @@ ]]> </programlisting> </example> + <example> + <title>Obtention d'une clôture en utilisant la classe <classname>ReflectionMethod</classname></title> + <programlisting role='php'> +<![CDATA[ +<?php + +class Exemple { + static function printer () { + echo "Bonjour le Monde!\n"; + } +} + +$class = new ReflectionClass('Exemple'); +$method = $class->getMethod('printer'); +$closure = $method->getClosure(); /* Depuis PHP 5.3.0 */ +$closure(); // Bonjour le Monde! + +?> +]]> + </programlisting> + </example> <note> <simpara> Invoquer des méthodes privées, protégées ou abstraites provoquera @@ -708,15 +722,14 @@ de faire du <literal>reverse-engineering</literal> sur les propriétés des classes. </para> - <example> - <title>La classe <classname>ReflectionProperty</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionProperty implements Reflector { final private __clone() - public __construct(mixed class, string name) + public void __construct(mixed class, string name) public string __toString() public static string export(mixed class, string name, bool return) public string getName() @@ -725,6 +738,7 @@ public bool isProtected() public bool isStatic() public bool isDefault() + public void setAccessible() /* Depuis PHP 5.3.0 */ public int getModifiers() public mixed getValue(stdclass object) public void setValue(stdclass object, mixed value) @@ -734,10 +748,11 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <simpara> <function>getDocComment</function> a été ajouté en PHP 5.1.0. + <function>setAccessible</function> a été ajouté en PHP 5.3.0. </simpara> </note> <para> @@ -791,6 +806,32 @@ ]]> </programlisting> </example> + <example> + <title>Obtenir la valeur d'une propriété privée et protégée en utilisant la classe <classname>ReflectionProperty</classname></title> + <programlisting role='php'> +<![CDATA[ +<?php + +class Foo { + public $x = 1; + protected $y = 2; + private $z = 3; +} + +$obj = new Foo; + +$prop = new ReflectionProperty('Foo', 'y'); +$prop->setAccessible(true); /* Depuis PHP 5.3.0 */ +var_dump($prop->getValue($obj)); // int(2) + +$prop = new ReflectionProperty('Foo', 'z'); +$prop->setAccessible(true); /* Depuis PHP 5.3.0 */ +var_dump($prop->getValue($obj)); // int(2) + +?> +]]> + </programlisting> + </example> <note> <simpara> Essayer de récupérer ou de définir les valeurs des propriétés d'une classe @@ -807,15 +848,13 @@ connaître toutes les extensions chargées à l'exécution en utilisation la fonction <function>get_loaded_extensions</function>. </para> - <example> - <title>La classe <classname>ReflectionExtension</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php -class ReflectionExtension implements Reflector -{ +class ReflectionExtension implements Reflector { final private __clone() - public __construct(string name) + public void __construct(string name) public string __toString() public static string export(string name, bool return) public string getName() @@ -830,7 +869,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <para> Pour connaître le fonctionnement d'une extension, vous devez d'abord créer une instance de la classe <classname>ReflectionExtension</classname>. Vous @@ -841,7 +880,7 @@ <programlisting role='php'> <![CDATA[ <?php -// Création d'une instance de la classe ReflectionProperty +// Création d'une instance de la classe ReflectionExtension $ext = new ReflectionExtension('standard'); // Affichage d'informations basiques @@ -849,6 +888,7 @@ "Nom : %s\n". "Version : %s\n". "Fonctions : [%d] %s\n". + "Constantes : [%d] %s\n" . "Entrées INI : [%d] %s\n" . "Classes : [%d] %s\n", $ext->getName(), @@ -886,7 +926,6 @@ <?php /** * Ma classe Reflection_Method - * */ class My_Reflection_Method extends ReflectionMethod { @@ -953,4 +992,4 @@ vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> \ No newline at end of file +--> http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/static.xml?r1=1.22&r2=1.23&diff_format=u Index: phpdoc-fr/language/oop5/static.xml diff -u phpdoc-fr/language/oop5/static.xml:1.22 phpdoc-fr/language/oop5/static.xml:1.23 --- phpdoc-fr/language/oop5/static.xml:1.22 Sun Jun 8 18:44:27 2008 +++ phpdoc-fr/language/oop5/static.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.22 $ --> -<!-- EN-Revision: 1.17 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.23 $ --> +<!-- EN-Revision: 1.19 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <sect1 xml:id="language.oop5.static" xmlns="http://docbook.org/ns/docbook"> @@ -37,6 +37,14 @@ </para> <para> + Comme n'importe quelle autre variable PHP statique, les propriétés statiques ne peuvent être + initialisées qu'en utilisant un litéral ou une constante; les expressions ne sont pas + permises. Ainsi, vous pouvez initialiser une propriété statique avec un + entier ou un tableau, mais ni avec une autre variable, ni avec une valeur de retour, + ni avec un objet. + </para> + + <para> Depuis PHP 5.3.0, il est possible de référencer la classe en utilisant une variable. La valeur de la variable ne peut être un mot clé (e.g. <literal>self</literal>, <literal>parent</literal> et <literal>static</literal>). @@ -123,4 +131,4 @@ vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> \ No newline at end of file +-->
http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5.xml?r1=1.18&r2=1.19&diff_format=u Index: phpdoc-fr/language/oop5.xml diff -u phpdoc-fr/language/oop5.xml:1.18 phpdoc-fr/language/oop5.xml:1.19 --- phpdoc-fr/language/oop5.xml:1.18 Mon Dec 1 16:24:37 2008 +++ phpdoc-fr/language/oop5.xml Wed Dec 3 23:09:25 2008 @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.18 $ --> -<!-- EN-Revision: 1.15 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.19 $ --> +<!-- EN-Revision: 1.16 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <chapter xml:id="language.oop5" xmlns="http://docbook.org/ns/docbook"> <title>Les classes et les objets (PHP 5)</title> - <sect1 xml:id="op5.intro"> + <sect1 xml:id="oop5.intro"> <title>Introduction</title> <para> En PHP 5, il y a un tout nouveau modèle objet. La gestion des objets en PHP http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/context/http.xml?r1=1.6&r2=1.7&diff_format=u Index: phpdoc-fr/language/context/http.xml diff -u phpdoc-fr/language/context/http.xml:1.6 phpdoc-fr/language/context/http.xml:1.7 --- phpdoc-fr/language/context/http.xml:1.6 Thu Aug 21 23:01:26 2008 +++ phpdoc-fr/language/context/http.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> -<!-- EN-Revision: 1.4 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.7 $ --> +<!-- EN-Revision: 1.5 Maintainer: yannick Status: ready --> <!-- Reviewed: no --> <refentry xml:id="context.http" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" role="noversion"> @@ -204,6 +204,8 @@ Ajout la possibilité d'utiliser des proxy HTTPS via des proxy HTTP. </entry> + </row> + <row> <entry>5.1.0</entry> <entry> Ajout du paramètre <parameter>max_redirects</parameter>. http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/interfaces.xml?r1=1.12&r2=1.13&diff_format=u Index: phpdoc-fr/language/oop5/interfaces.xml diff -u phpdoc-fr/language/oop5/interfaces.xml:1.12 phpdoc-fr/language/oop5/interfaces.xml:1.13 --- phpdoc-fr/language/oop5/interfaces.xml:1.12 Sun Jul 22 17:16:11 2007 +++ phpdoc-fr/language/oop5/interfaces.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.12 $ --> -<!-- EN-Revision: 1.10 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.13 $ --> +<!-- EN-Revision: 1.14 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <sect1 xml:id="language.oop5.interfaces" xmlns="http://docbook.org/ns/docbook"> @@ -30,6 +30,19 @@ fonctions, puisque cela causerait une ambiguïté. </para> </note> + <note> + <para> + Les interfaces peuvent être étendues comme des classes en utilisant l'opérateur <literal>extend</literal>. + </para> + </note> + </sect2> + <sect2 xml:id="language.oop5.interfaces.constants"> + <title><literal>Les constantes</literal></title> + <para> + Les interfaces peuvent contenir des constantes. Les constantes d'interfaces fonctionnent exactement + comme les <link linkend="language.oop5.constants">constantes de classe</link>. Elles ne peuvent pas + être écrasées par des classes ou des interfaces qui en héritent. + </para> </sect2> <sect2 xml:id="language.oop5.interfaces.examples"> &reftitle.examples; @@ -38,6 +51,7 @@ <programlisting role="php"> <![CDATA[ <?php + // Declaration de l'interface 'iTemplate' interface iTemplate { @@ -82,12 +96,118 @@ ]]> </programlisting> </example> + <example xml:id="language.oop5.interfaces.examples.ex2"> + <title>Les interfaces extensibles</title> + <programlisting role="php"> +<![CDATA[ +<?php +interface a +{ + public function foo(); +} + +interface b extends a +{ + public function baz(Baz $baz); +} + +// Ceci ne fonctionnera pas +class c implements b +{ + public function foo() + { + } + + public function baz(Baz $baz) + { + } +} + +// Ceci ne fonctionnera pas et soulèvera une erreur fatale +class d implements b +{ + public function foo() + { + } + + public function baz(Foo $foo) + { + } +} +?> +]]> + </programlisting> + </example> + <example xml:id="language.oop5.interfaces.examples.ex3"> + <title>L'héritage de plusieurs interfaces</title> + <programlisting role="php"> +<![CDATA[ +<?php +interface a +{ + public function foo(); +} + +interface b +{ + public function bar(); +} + +interface c extends a, b +{ + public function baz(); +} + +class d implements c +{ + public function foo() + { + } + + public function bar() + { + } + + public function baz() + { + } +} +?> +]]> + </programlisting> + </example> + <example xml:id="language.oop5.interfaces.examples.ex4"> + <title>Les interfaces avec des constantes</title> + <programlisting role="php"> +<![CDATA[ +<?php +interface a +{ + const b = 'Constante de l\'interface'; +} + +// Affiche: Constante de l'interface +echo a::b; + + +// Ceci ne fonctionnera pas de toutes façons vu qu'il n'est pas autorisé +// d'écraser des constantes. C'est le même principe qu'avec les constantes +// de classe +class b implements a +{ + const b = 'Constante de classe'; +} +?> +]]> + </programlisting> + </example> <simpara> Voir aussi l'opérateur <link linkend="language.operators.type">instanceof</link>. </simpara> </sect2> -</sect1> + + </sect1> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/overloading.xml?r1=1.28&r2=1.29&diff_format=u Index: phpdoc-fr/language/oop5/overloading.xml diff -u phpdoc-fr/language/oop5/overloading.xml:1.28 phpdoc-fr/language/oop5/overloading.xml:1.29 --- phpdoc-fr/language/oop5/overloading.xml:1.28 Sun Jun 8 07:02:08 2008 +++ phpdoc-fr/language/oop5/overloading.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.28 $ --> -<!-- EN-Revision: 1.30 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.29 $ --> +<!-- EN-Revision: 1.32 Maintainer: yannick Status: ready --> <!-- Reviewed: no --> <sect1 xml:id="language.oop5.overloading" xmlns="http://docbook.org/ns/docbook"> @@ -69,6 +69,7 @@ <entry>5.3.0</entry> <entry> Ajout de <literal>__callStatic()</literal>. + Ajout d'un avertissement pour forcer la visibilité <literal>public</literal> et la déclaration non <literal>static</literal>. </entry> </row> </tbody> @@ -145,7 +146,7 @@ /** La surcharge n'est pas utilisée sur les membres déclarés. */ public $declared = 1; - /** La surcharge n'est pas lancée lorsque l'on accède à la classe. */ + /** La surcharge n'est lancée que lorsque l'on accède à la classe depuis l'extérieur. */ private $hidden = 2; public function __set($name, $value) { @@ -161,7 +162,7 @@ $trace = debug_backtrace(); trigger_error( - 'Propriété non-définie : ' . $name . + 'Propriété non-définie via __get(): ' . $name . ' dans ' . $trace[0]['file'] . ' à la ligne ' . $trace[0]['line'], E_USER_NOTICE); @@ -182,7 +183,6 @@ /** Ce n'est pas une méthode magique, nécessaire ici que pour l'exemple. */ public function getHidden() { - echo "'hidden' visible ici, donc __get() non utilisé\n"; return $this->hidden; } } @@ -193,14 +193,19 @@ $obj = new MemberTest; $obj->a = 1; -echo $obj->a . "\n"; +echo $obj->a . "\n\n"; var_dump(isset($obj->a)); unset($obj->a); var_dump(isset($obj->a)); +echo "\n"; -echo $obj->declared . "\n"; +echo $obj->declared . "\n\n"; + +echo "Manipulons maintenant la propriété privée nommée 'hidden':\n"; +echo "'hidden' est visible depuis la classe, donc __get() n'est pas utilisé...\n"; echo $obj->getHidden() . "\n"; +echo "'hidden' n'est pas visible en dehors de la classe, donc __get() est utlisé...\n"; echo $obj->hidden . "\n"; ?> ]]> @@ -211,18 +216,23 @@ Définition de 'a' à '1' Récupération de 'a' 1 + Est-ce que 'a' est défini ? bool(true) Effacement de 'a' Est-ce que 'a' est défini ? bool(false) + 1 -'hidden' visible ici, donc __get() non utilisé + +Manipulons maintenant la propriété privée nommée 'hidden': +'hidden' est visible depuis la classe, donc __get() n'est pas utilisé... 2 +'hidden' n'est pas visible en dehors de la classe, donc __get() est utlisé... Récupération de 'hidden' -Notice: Propriété non-définie : hidden dans <file> à la ligne 64 dans <file> à la ligne 28 +Notice: Propriété non-définie via __get(): hidden dans <file> à la ligne 64 dans <file> à la ligne 28 ]]> </screen> http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/reflection.xml?r1=1.33&r2=1.34&diff_format=u Index: phpdoc-fr/language/oop5/reflection.xml diff -u phpdoc-fr/language/oop5/reflection.xml:1.33 phpdoc-fr/language/oop5/reflection.xml:1.34 --- phpdoc-fr/language/oop5/reflection.xml:1.33 Sun Jun 8 18:44:27 2008 +++ phpdoc-fr/language/oop5/reflection.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.33 $ --> -<!-- EN-Revision: 1.35 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.34 $ --> +<!-- EN-Revision: 1.39 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <sect1 xml:id="language.oop5.reflection" xmlns="http://docbook.org/ns/docbook"> @@ -34,8 +34,7 @@ L'API de réflexion est une extension orientée objet du Moteur Zend, constituée des classes suivantes : </para> - <example> - <title>API de réflexion</title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php @@ -52,7 +51,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <simpara> Pour plus de détails sur ces classes, lisez les chapitres suivants. @@ -96,7 +95,6 @@ Method [ <internal> final private method __clone ] { } - Method [ <internal, ctor> public method __construct ] { - Parameters [2] { @@ -170,8 +168,7 @@ La classe <classname>ReflectionFunction</classname> vous permet de faire du <literal>reverse-engineering</literal> sur les fonctions. </para> - <example> - <title>La classe <classname>ReflectionFunction</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php @@ -184,6 +181,7 @@ public string getName() public bool isInternal() public bool isDisabled() + public mixed getClosure() /* Depuis PHP 5.3.0 */ public bool isUserDefined() public string getFileName() public int getStartLine() @@ -200,7 +198,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <para> La classe parent <classname>ReflectionFunctionAbstract</classname> a les mêmes méthodes, exceptée <function>invoke</function>, <function>invokeArgs</function>, @@ -231,7 +229,6 @@ function counter() { static $c = 0; - return $c++; } @@ -286,15 +283,14 @@ La classe <classname>ReflectionParameter</classname> récupère les informations concernant les paramètres des fonctions ou des méthodes. </para> - <example> - <title>La classe <classname>ReflectionParameter</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionParameter implements Reflector { final private __clone() - public object __construct(string function, string parameter) + public void __construct(string function, string parameter) public string __toString() public static string export(mixed function, mixed parameter, bool return) public string getName() @@ -312,7 +308,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <para> <function>getDefaultValue</function>, @@ -375,15 +371,14 @@ de faire du <literal>reverse-engineering</literal> sur des classes et des interfaces. </para> - <example> - <title>La classe <classname>ReflectionClass</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionClass implements Reflector { final private __clone() - public object __construct(string name) + public void __construct(string name) public string __toString() public static string export(mixed class, bool return) public string getName() @@ -426,7 +421,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <simpara> <function>hasConstant</function>, <function>hasMethod</function>, @@ -458,7 +453,6 @@ /** * Une classe compteur - * */ class Compteur extends Object implements Linearisable { @@ -471,8 +465,7 @@ * @access public * @return int */ - public function count() - { + public function count() { return self::$c++; } } @@ -558,7 +551,7 @@ class ReflectionObject extends ReflectionClass { final private __clone() - public object __construct(mixed object) + public void __construct(mixed object) public string __toString() public static string export(mixed object, bool return) } @@ -574,14 +567,13 @@ La classe <classname>ReflectionMethod</classname> vous permet de faire du <literal>reverse-engineering</literal> sur les méthodes des classes. </para> - <example> - <title>La classe <classname>ReflectionMethod</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionMethod extends ReflectionFunctionAbstract implements Reflector { - public __construct(mixed class, string name) + public void __construct(mixed class, string name) public string __toString() public static string export(mixed class, string name, bool return) public mixed invoke(stdclass object [, mixed args [, ...]]) @@ -595,6 +587,7 @@ public bool isConstructor() public bool isDestructor() public int getModifiers() + public mixed getClosure() /* Depuis PHP 5.3.0 */ public ReflectionClass getDeclaringClass() // Inherited from ReflectionFunctionAbstract @@ -615,7 +608,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <para> Pour connaître le fonctionnement d'une méthode, vous devez d'abord créer une instance de la classe <classname>ReflectionMethod</classname>. Vous @@ -686,6 +679,27 @@ ]]> </programlisting> </example> + <example> + <title>Obtention d'une clôture en utilisant la classe <classname>ReflectionMethod</classname></title> + <programlisting role='php'> +<![CDATA[ +<?php + +class Exemple { + static function printer () { + echo "Bonjour le Monde!\n"; + } +} + +$class = new ReflectionClass('Exemple'); +$method = $class->getMethod('printer'); +$closure = $method->getClosure(); /* Depuis PHP 5.3.0 */ +$closure(); // Bonjour le Monde! + +?> +]]> + </programlisting> + </example> <note> <simpara> Invoquer des méthodes privées, protégées ou abstraites provoquera @@ -708,15 +722,14 @@ de faire du <literal>reverse-engineering</literal> sur les propriétés des classes. </para> - <example> - <title>La classe <classname>ReflectionProperty</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php class ReflectionProperty implements Reflector { final private __clone() - public __construct(mixed class, string name) + public void __construct(mixed class, string name) public string __toString() public static string export(mixed class, string name, bool return) public string getName() @@ -725,6 +738,7 @@ public bool isProtected() public bool isStatic() public bool isDefault() + public void setAccessible() /* Depuis PHP 5.3.0 */ public int getModifiers() public mixed getValue(stdclass object) public void setValue(stdclass object, mixed value) @@ -734,10 +748,11 @@ ?> ]]> </programlisting> - </example> + </informalexample> <note> <simpara> <function>getDocComment</function> a été ajouté en PHP 5.1.0. + <function>setAccessible</function> a été ajouté en PHP 5.3.0. </simpara> </note> <para> @@ -791,6 +806,32 @@ ]]> </programlisting> </example> + <example> + <title>Obtenir la valeur d'une propriété privée et protégée en utilisant la classe <classname>ReflectionProperty</classname></title> + <programlisting role='php'> +<![CDATA[ +<?php + +class Foo { + public $x = 1; + protected $y = 2; + private $z = 3; +} + +$obj = new Foo; + +$prop = new ReflectionProperty('Foo', 'y'); +$prop->setAccessible(true); /* Depuis PHP 5.3.0 */ +var_dump($prop->getValue($obj)); // int(2) + +$prop = new ReflectionProperty('Foo', 'z'); +$prop->setAccessible(true); /* Depuis PHP 5.3.0 */ +var_dump($prop->getValue($obj)); // int(2) + +?> +]]> + </programlisting> + </example> <note> <simpara> Essayer de récupérer ou de définir les valeurs des propriétés d'une classe @@ -807,15 +848,13 @@ connaître toutes les extensions chargées à l'exécution en utilisation la fonction <function>get_loaded_extensions</function>. </para> - <example> - <title>La classe <classname>ReflectionExtension</classname></title> + <informalexample> <programlisting role="php"> <![CDATA[ <?php -class ReflectionExtension implements Reflector -{ +class ReflectionExtension implements Reflector { final private __clone() - public __construct(string name) + public void __construct(string name) public string __toString() public static string export(string name, bool return) public string getName() @@ -830,7 +869,7 @@ ?> ]]> </programlisting> - </example> + </informalexample> <para> Pour connaître le fonctionnement d'une extension, vous devez d'abord créer une instance de la classe <classname>ReflectionExtension</classname>. Vous @@ -841,7 +880,7 @@ <programlisting role='php'> <![CDATA[ <?php -// Création d'une instance de la classe ReflectionProperty +// Création d'une instance de la classe ReflectionExtension $ext = new ReflectionExtension('standard'); // Affichage d'informations basiques @@ -849,6 +888,7 @@ "Nom : %s\n". "Version : %s\n". "Fonctions : [%d] %s\n". + "Constantes : [%d] %s\n" . "Entrées INI : [%d] %s\n" . "Classes : [%d] %s\n", $ext->getName(), @@ -886,7 +926,6 @@ <?php /** * Ma classe Reflection_Method - * */ class My_Reflection_Method extends ReflectionMethod { @@ -953,4 +992,4 @@ vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> \ No newline at end of file +--> http://cvs.php.net/viewvc.cgi/phpdoc-fr/language/oop5/static.xml?r1=1.22&r2=1.23&diff_format=u Index: phpdoc-fr/language/oop5/static.xml diff -u phpdoc-fr/language/oop5/static.xml:1.22 phpdoc-fr/language/oop5/static.xml:1.23 --- phpdoc-fr/language/oop5/static.xml:1.22 Sun Jun 8 18:44:27 2008 +++ phpdoc-fr/language/oop5/static.xml Wed Dec 3 23:09:25 2008 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.22 $ --> -<!-- EN-Revision: 1.17 Maintainer: yannick Status: ready --> +<!-- $Revision: 1.23 $ --> +<!-- EN-Revision: 1.19 Maintainer: yannick Status: ready --> <!-- Reviewed: yes --> <sect1 xml:id="language.oop5.static" xmlns="http://docbook.org/ns/docbook"> @@ -37,6 +37,14 @@ </para> <para> + Comme n'importe quelle autre variable PHP statique, les propriétés statiques ne peuvent être + initialisées qu'en utilisant un litéral ou une constante; les expressions ne sont pas + permises. Ainsi, vous pouvez initialiser une propriété statique avec un + entier ou un tableau, mais ni avec une autre variable, ni avec une valeur de retour, + ni avec un objet. + </para> + + <para> Depuis PHP 5.3.0, il est possible de référencer la classe en utilisant une variable. La valeur de la variable ne peut être un mot clé (e.g. <literal>self</literal>, <literal>parent</literal> et <literal>static</literal>). @@ -123,4 +131,4 @@ vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> \ No newline at end of file +-->