|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47664 get_class returns NULL instead of FALSE.
Submitted: 2009-03-15 15:13 UTC Modified: 2013-08-06 09:48 UTC
Avg. Score:4.3 ± 1.2
Reproduced:17 of 19 (89.5%)
Same Version:11 (64.7%)
Same OS:6 (35.3%)
From: wiebe at wiebelt dot nl Assigned: dmitry (profile)
Status: Closed Package: Class/Object related
PHP Version: master OS: any
Private report: No CVE-ID: None
 [2009-03-15 15:13 UTC] wiebe at wiebelt dot nl
get_class returns NULL when using it with a string instead of FALSE.

Reproduce code:

Expected result:

Actual result:
Warning: get_class() expects parameter 1 to be object, string given in 
/home/wiebe/run.php on line 34


db (last revision 2013-06-03 21:15 UTC by Hannahcooper at myself dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-15 15:22 UTC]
invalid argument returns NULL, not false.
 [2009-03-15 17:44 UTC] wiebe at wiebelt dot nl
The documentation says it should return false.

"Returns the name of the class of which object is an instance. Returns 
FALSE if object is not an object."

It's very inconsistent if in PHP 5.2 it returns false and in 5.3 null.
 [2009-03-15 18:10 UTC]
hm, you are right. It should remain the same especially as it is documented. Dmitry?
 [2009-03-16 09:53 UTC]
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
Thank you for the report, and for helping us make PHP better.

 [2009-06-23 11:19 UTC]
This isn't fixed, the warning is still there which is a part of the problem here.
 [2009-06-30 12:33 UTC]
I've a patch at:
 [2009-07-28 13:06 UTC]
I would prefer to stay the warning, as it indicates a problem in user code that probably need to be fixed.
 [2009-07-28 13:14 UTC]
The documentation clearly states:

"Returns the name of the class of which object is an instance. Returns
FALSE if object is not an object."

It doesn't say "shows a warning when object is not an object", so this should be fixed according to what PHP 5.2.x and the manual say.

 [2013-08-06 09:48 UTC]
-Status: Assigned +Status: Closed -Type: Bug +Type: Feature/Change Request -Operating System: Ubuntu 8.10 +Operating System: any -PHP Version: 5.3.0beta1 +PHP Version: master
 [2013-08-06 09:48 UTC]
It is documented as get_class() raise E_WARNING now.
I feel E_WARNING is unnecessary for get_class() as it requires is_object() call 
for error free programming. e.g. factory may fail and return false when 
something wrong, etc.

Anyway, bug is fixed and E_WARNING error is documented. If anyone feel it should 
not raise E_WARNING, create new entry for it.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 20:01:27 2023 UTC