- Added information about NULL as the default parameter value

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@257695 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Felipe Pena 2008-04-16 16:31:45 +00:00
parent 63678b51e4
commit f5ca557b90

View file

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<sect1 xml:id="language.oop5.typehinting" xmlns="http://docbook.org/ns/docbook">
<title>Type Hinting</title>
<para>
PHP 5 introduces Type Hinting. Functions are now able to force parameters
to be objects (by specifying the name of the class in the function
prototype) or arrays (since PHP 5.1).
prototype) or arrays (since PHP 5.1). However, if <type>NULL</type> is used
as the default parameter value, it will be allowed as an argument for any
later call.
</para>
<example>
@ -97,6 +99,24 @@ function MyFunction (MyClass $foo) {
// Works
$myclass = new MyClass;
MyFunction($myclass);
?>
]]>
</programlisting>
<para>
Type hinting allowing NULL value:
</para>
<programlisting role="php">
<![CDATA[
<?php
/* Accepting NULL value */
function test(stdClass $obj = NULL) {
}
test(NULL);
test(new stdClass);
?>
]]>
</programlisting>