Edit report at https://bugs.php.net/bug.php?id=64744&edit=1
ID: 64744 Updated by: larue...@php.net Reported by: mgraham at etsy dot com Summary: Differentiate between member function call on a null and non-null, non-objects -Status: Open +Status: Feedback Type: Feature/Change Request Package: Class/Object related Operating System: Linux PHP Version: 5.4.14 Block user comment: N Private report: N New Comment: I am not sure why this is important? the error is a FATAL error, when it occurs, the only important reason is "it's not a object", and as for what exactlly type it is, doesn't matter, and won't help much either... Previous Comments: ------------------------------------------------------------------------ [2013-04-30 16:19:52] mgraham at etsy dot com Description: ------------ The error message for "Call to a member function on a non-object" is not as helpful as it could be. It would be really great if it would distinguish when the variable is null instead of another type of actual data such as an integer, string or array. This is helpful so that when fixing this issues, one can tell from the logs if a null check is sufficient or if I need to find out where the wrong type of data is being created. Test script: --------------- <?php $x = (isset($argv[1]) && $argv[1] == 'null') ? null : 'non-null-non-object'; $x->fail(); Expected result: ---------------- Null is a special kind of non-object, so if the variable is null, the error message should be different to indicate that it's null. mgraham@vm:~/development/tmp$ php bug.php null Fatal error: Call to a member function fail() on null in /home/mgraham/development/tmp/bug.php on line 3 mgraham@vm:~/development/tmp$ php bug.php Fatal error: Call to a member function fail() on a non-object in /home/mgraham/development/tmp/bug.php on line 3 mgraham@vm:~/development/tmp$ Even better would be to say in the error message what the type of the variable is for, integer, array, string, whatever. Actual result: -------------- When running this script, there is no information about what type of non-object it was. mgraham@vm:~/development/tmp$ php bug.php null Fatal error: Call to a member function fail() on a non-object in /home/mgraham/development/tmp/bug.php on line 3 mgraham@vm:~/development/tmp$ php bug.php Fatal error: Call to a member function fail() on a non-object in /home/mgraham/development/tmp/bug.php on line 3 mgraham@vm:~/development/tmp$ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64744&edit=1