php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29930 Type hint error message should reveal both class names
Submitted: 2004-09-01 13:56 UTC Modified: 2006-09-18 15:02 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: reiersol at online dot no Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.1 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: reiersol at online dot no
New email:
PHP Version: OS:

 

 [2004-09-01 13:56 UTC] reiersol at online dot no
Description:
------------
When you have a type-hint error, the error message reports only the class the object should be, not the type it actually is:

Argument 1 must be an instance of Bar in hints.php on line 3

My experience so far indicates it would be tremendously helpful in debugging to know what class the object actually belongs to. As it is, I have to to *remove* the type hint and add a test inside the method to get that information. (I typically throw an exception to get a full stack trace.)


Reproduce code:
---------------
class Foo {
    public function process(Bar $bar) {}
}
class Bar {}
class Baz {}
$foo = new Foo;
$foo->process(new Baz);


Expected result:
----------------
Desired result:

Argument 1 is an instance of Baz, must be an instance of Bar in hints.php on line 3

Actual result:
--------------
Argument 1 must be an instance of Bar in hints.php on line 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-18 15:02 UTC] bjori@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Catchable fatal error: Argument 1 passed to Foo::process() 
must be an instance of Bar, instance of Baz given, called 
in...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 15:01:27 2024 UTC