php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26780 Undefined variables cause type hints to become useless
Submitted: 2004-01-04 02:00 UTC Modified: 2006-01-02 09:03 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: jebmc at iprimus dot com dot au Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.* OS: *
Private report: No CVE-ID: None
 [2004-01-04 02:00 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-04 05:12 UTC] 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.
 [2006-01-02 09:03 UTC] sniper@php.net
There is better error message now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 22:01:26 2024 UTC