hi all,

we are encountering an error in our code due to type hint semantics.  php is
allowing NULL values through a type hint for a class, however, if i read the
manual, NULL, should only be allowed, if and only if, null is given as the
default value for the formal parameter that is type-hinted.

"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). However, if
NULL<http://ch2.php.net/manual/en/language.types.null.php>is used as
the default parameter value, it will be allowed as an argument
for any later call."

now, i have checked our code; there is no NULL default value, and there are
no parents which mark a default value of NULL.  so why would they be
creeping through then.. ?

well, i glanced at the phpt test, and its quite clear the tests are allowing
NULL,

Zend/tests/errmsg_013.phpt:errmsg: default value for parameters with array
type hint can only be an array or NULL
Zend/tests/errmsg_013.phpt:Fatal error: Default value for parameters with
array type hint can only be an array or NULL in %s on line %d

looking at the function prototype in this test, NULL is not specefied as the
default value, so i dont think NULL should be allowed here anyway..
--TEST--
errmsg: default value for parameters with array type hint can only be an
array or NULL
--FILE--
<?php

class test {
    function foo(array $a = "s") {
    }
}

echo "Done\n";
?>
--EXPECTF--
Fatal error: Default value for parameters with array type hint can only be
an array or NULL in %s on line %d

this taken from 5.2.6.RC3 source.  it seems to me, either the source or the
manual is wrong, but which one is it ??  personally, i would prefer it be
the former in this case ;)

FWIW, we are currently running php5.2.2 on centos5, but im pretty sure an
upgrade to 5.2.6 will not change the semantics, since the phpt tests were
the same in both the 5.2.2 & 5.2.6 source.

-nathan

Reply via email to