aidan           Sun Oct  3 00:36:36 2004 EDT

  Added files:                 
    /phpdoc/en/language/oop5    typehinting.xml 
  Log:
  Initial Commit
  

http://cvs.php.net/co.php/phpdoc/en/language/oop5/typehinting.xml?r=1.1&p=1
Index: phpdoc/en/language/oop5/typehinting.xml
+++ phpdoc/en/language/oop5/typehinting.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
 <sect1 id="language.oop5.typehinting">
  <title>Type Hinting</title>
  <para>
   PHP 5 introduces Type Hinting. Methods are now able to force parameters
   to be objects by specifying the name of the class in the function prototype.
  </para>
  
  <example>
   <title>Type Hinting example</title>
    <programlisting role="php">
<![CDATA[
<?php
class MyClass
{
    /**
     * A test function
     *
     * First parameter must be an object of type OtherClass
     */
    public function test(OtherClass $otherclass) {
        echo $otherclass->var;
    }
}

class OtherClass {
    public $var = 'Hello World';
}

$myclass = new MyClass;

// These are fatal errors
// Argument 1 must be an object of class OtherClass
$myclass->test('hello');
// Argument 1 must be an instance of OtherClass
$foo = new stdClass;
$myclass->test($foo);
// Argument 1 must not be null
$myclass->test(null);

// This is fine
$foo = new OtherClass;
// Prints Hello World
$myclass->test($foo);
?> 
]]>
   </programlisting>
  </example>
 </sect1>
 
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

Reply via email to