ID: 26780 Comment by: php at kaiundina dot de Reported By: jebmc at iprimus dot com dot au Status: Suspended Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5.0.* New Comment:
I've a similar problem related to optional parameters. Since null-values are not accepted for parameters using type-hints, it seems to be impossible to create optional parameters! following case: <?php class Foo { } function myFunc($param1, Foo $bar = null) { echo $param1; } myFunc('This is a test'); ?> doesn't work and results in: Fatal error: Argument 2 must not be null in C:\Projekte\www\test\typehints.php5 on line 6 the following workaround I tried is also disallowed: $x = new Foo(); function myFunc($param1, Foo $bar = $x) and results in: Parse error: parse error, unexpected T_VARIABLE in C:\Projekte\www\test\typehints.php5 on line 8 I think type hints should pass null-values like it is in Java and C# for allowance of optional object parameters. On the other hand 'is_a()' and 'instanceof' should return false, to have a chance to determine if an object is capable of doing specific operations. Just my point of view ;) Let me know, if things change... thanks Previous Comments: ------------------------------------------------------------------------ [2004-01-04 05:12:13] [EMAIL PROTECTED] The undefined variable is a NULL value when passed to the functionand at the moment type hints accept NULL values. I strongly disagreee here and we are still discussing about a notation to decide whether to accpet or block NULL values with type hints. ------------------------------------------------------------------------ [2004-01-04 02:00:15] jebmc at iprimus dot com dot au Description: ------------ If you pass an undefined variable as the value of a type-hinted argument, the type-hint checking appears to be skipped. Rather, a notice error is printed for the undefined variable (as it should be) and the function or method happily continues on. Reproduce code: --------------- <?php class Foo { } function myFunc($param1, Foo $bar) { echo $param1; } myFunc('This is a test',$badVariable); ?> Expected result: ---------------- "Notice: Undefined variable: badVariable in foo.php on line 11 Fatal error: Argument 2 must be an object of class foo in foo.php on line 6" Actual result: -------------- "Notice: Undefined variable: badVariable in foo.php on line 11 This is a test" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26780&edit=1