php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32505 Type hinting still a useless feature
Submitted: 2005-03-30 17:19 UTC Modified: 2006-04-03 13:49 UTC
From: pornel at despammed dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.3 OS: any
Private report: No CVE-ID: None
 [2005-03-30 17:19 UTC] pornel at despammed dot com
Description:
------------
Fatal error: Argument $n must (not be null|be an object of class $c) in $location_of_called_function

These errros point to location of called function, but not to location *where it was called from*. 

In most cases fault is in calling code, not function declaration, so given file/line is irrelevant.

The problem is that it is not possible to figure out where from the function has been called and actually makes type hinting more harmful than useful.

Previous WONTFIX bug is wrong (#28001), because it's not possible to use debug_backtrace() it this situation.

WONTFIX bug #31578, concludes that debug_backtrace() doesn't work here by design.

One similar bug says it has been fixed long time ago (#27290), but actually the original problem is not yet fixed (see testcase).


The solution is to make type hint error non-fatal (so handler and debug_backtrace can be used) or report location of calling function (back up one level on stack).


Reproduce code:
---------------
<?php

function Foo(Bar $x) // definition, line 3
{
}

Foo(NULL); // call, line 7



Expected result:
----------------
Fatal error: Argument 1 must not be null in test.php on line 7

Actual result:
--------------
Fatal error: Argument 1 must not be null in test.php on line 3

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-03 13:49 UTC] tony2001@php.net
Fixed long time ago:
.. called in <file> on line 7 and defined in <file> on line 3
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Aug 16 19:01:28 2024 UTC