php.net |  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
Votes:21
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
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: wiebe at wiebelt dot nl
New email:
PHP Version: OS:

 

 [2009-03-15 15:13 UTC] wiebe at wiebelt dot nl
Description:
------------
get_class returns NULL when using it with a string instead of FALSE.

Reproduce code:
---------------
<?php
var_dump(get_class('test'));

Expected result:
----------------
bool(false)






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

Patches

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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-15 15:22 UTC] pajoye@php.net
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] pajoye@php.net
hm, you are right. It should remain the same especially as it is documented. Dmitry?
 [2009-03-16 09:53 UTC] dmitry@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.


 [2009-06-23 11:19 UTC] derick@php.net
This isn't fixed, the warning is still there which is a part of the problem here.
 [2009-06-30 12:33 UTC] derick@php.net
I've a patch at: http://php.pastebin.com/m20d61023
 [2009-07-28 13:06 UTC] dmitry@php.net
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] derick@php.net
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] yohgaki@php.net
-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] yohgaki@php.net
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.

Closing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 07:01:29 2024 UTC