cvs: phpdoc /en/language operators.xml

From: Date: Wed, 23 Apr 2008 03:44:08 +0000
Subject: cvs: phpdoc /en/language operators.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-1557@lists.php.net to get a copy of this message
felipe Wed Apr 23 03:44:08 2008 UTC Modified files: /phpdoc/en/language operators.xml Log: + Fixed |-- Indentation |-- Markup (missing some <para>s) - Cosmetic (add blank lines in examples) http://cvs.php.net/viewvc.cgi/phpdoc/en/language/operators.xml?r1=1.123&r2=1.124&diff_format=u Index: phpdoc/en/language/operators.xml diff -u phpdoc/en/language/operators.xml:1.123 phpdoc/en/language/operators.xml:1.124 --- phpdoc/en/language/operators.xml:1.123 Fri Apr 18 13:34:30 2008 +++ phpdoc/en/language/operators.xml Wed Apr 23 03:44:08 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.123 $ --> +<!-- $Revision: 1.124 $ --> <chapter xml:id="language.operators" xmlns="http://docbook.org/ns/docbook"> <title>Operators</title> <simpara> @@ -1192,11 +1192,12 @@ <example> <title>Using instanceof with classes</title> <programlisting role="php"> - <![CDATA[ +<![CDATA[ <?php class MyClass { } + class NotMyClass { } @@ -1205,44 +1206,50 @@ var_dump($a instanceof MyClass); var_dump($a instanceof NotMyClass); ?> - ]]> - </programlisting> - &example.outputs; - <screen> +]]> + </programlisting> + &example.outputs; + <screen> <![CDATA[ bool(true) bool(false) ]]> </screen> </example> + </para> + <para> <literal>instanceof</literal> can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class: <example> <title>Using instanceof with inherited classes</title> <programlisting role="php"> - <![CDATA[ +<![CDATA[ <?php class ParentClass { } + class MyClass extends ParentClass { } + $a = new MyClass; var_dump($a instanceof MyClass); var_dump($a instanceof ParentClass); ?> - ]]> - </programlisting> - &example.outputs; - <screen> +]]> + </programlisting> + &example.outputs; + <screen> <![CDATA[ bool(true) bool(true) ]]> </screen> </example> + </para> + <para> To check if an object is <emphasis>not</emphasis> an instanceof a class, the <link linkend="language.operators.logical">logical <literal>not</literal> operator</link> can be used. @@ -1255,6 +1262,7 @@ class MyClass { } + $a = new MyClass; var_dump(!($a instanceof stdClass)); ?> @@ -1267,29 +1275,33 @@ ]]> </screen> </example> + </para> + <para> Lastly, <literal>instanceof</literal> can also be used to determine whether a variable is an instantiated object of a class that implements an <link linkend="language.oop5.interfaces">interface</link>: <example> <title>Using instanceof for class</title> <programlisting role="php"> - <![CDATA[ +<![CDATA[ <?php interface MyInterface { } + class MyClass implements MyInterface { } + $a = new MyClass; var_dump($a instanceof MyClass); var_dump($a instanceof MyInterface); ?> - ]]> - </programlisting> - &example.outputs; - <screen> +]]> + </programlisting> + &example.outputs; + <screen> <![CDATA[ bool(true) bool(true) @@ -1303,23 +1315,26 @@ <example> <title>Using instanceof with other variables</title> <programlisting role="php"> - <![CDATA[ +<![CDATA[ <?php interface MyInterface { } + class MyClass implements MyInterface { } + $a = new MyClass; $b = new MyClass; $c = 'MyClass'; $d = 'NotMyClass'; + var_dump($a instanceof $b); // $b is an object of class MyClass var_dump($a instanceof $c); // $c is a string 'MyClass' var_dump($a instanceof $d); // $d is a string 'NotMyClass' ?> - ]]> +]]> </programlisting> &example.outputs; <screen> @@ -1340,7 +1355,7 @@ <example> <title>Avoiding classname lookups and fatal errors with instanceof in PHP 5.0</title> <programlisting role="php"> - <![CDATA[ +<![CDATA[ <?php $d = 'NotMyClass'; var_dump($a instanceof $d); // no fatal error here

« previous php.doc.cvs (#1557) next »