Edit report at https://bugs.php.net/bug.php?id=64744&edit=1

 ID:                 64744
 User updated by:    mgraham at etsy dot com
 Reported by:        mgraham at etsy dot com
 Summary:            Differentiate between member function call on a null
                     and non-null, non-objects
-Status:             Feedback
+Status:             Open
 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:

The reason it's useful is that knowing it's null, rather than "a string" 
provides a great deal more information about how to fix it.

null can be considered a related type to whatever object I'm expecting, whereas 
a string or integer or array are totally different types of objects.

Consider this in a language like C++ for example:
SomeClass and SomeClass * are related types, but vector< int > is completely 
unrelated. If I get null for SomeClass *, then it's just an invalid value of 
type SomeClass *. I can check for that value and be done. If I'm getting 
another 
type altogether, then I have some other kind of problem that requires 
additional 
investigation.

The reason this is important is that it distinguishes between whether my 
variable is of the right type, but has the wrong value, or is it not even of 
the 
right type. Knowing that would make a lot of these kinds of errors much easier 
to fix.


Previous Comments:
------------------------------------------------------------------------
[2013-05-03 14:57:37] larue...@php.net

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...

------------------------------------------------------------------------
[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

Reply via email to