#26780 [Sus->Csd]: Undefined variables cause type hints to become useless

From: Date: Mon, 02 Jan 2006 08:03:39 +0000
Subject: #26780 [Sus->Csd]: Undefined variables cause type hints to become useless
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-91339@lists.php.net to get a copy of this message
ID: 26780 Updated by: sniper@php.net Reported By: jebmc at iprimus dot com dot au -Status: Suspended +Status: Closed Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.0.* New Comment: There is better error message now. Previous Comments: ------------------------------------------------------------------------ [2004-01-04 05:12:13] helly@php.net 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

« previous php.bugs (#91339) next »