|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20932 Class without member variables gives "empty"/"null" objects
Submitted: 2002-12-11 04:47 UTC Modified: 2002-12-11 06:05 UTC
From: richter at cyperfection dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.2.3 OS: Windows XP
Private report: No CVE-ID: None
 [2002-12-11 04:47 UTC] richter at cyperfection dot de
take the following example:


class MethodsOnly {
	//var $dummy;
	function doSomething() {
		print("OBJ: doing something\n");
}// class

$OBJ = new MethodsOnly();
print("empty(OBJ):   ".(empty($OBJ) ? "true" : "false")."\n");
print("OBJ == null:  ".(($OBJ == null) ? "true" : "false")."\n");
print("OBJ === null: ".(($OBJ === null) ? "true" : "false")."\n");


it gives the following output:

OBJ: doing something
empty(OBJ):   true
OBJ == null:  true
OBJ === null: false

now, if you uncomment the $dummy member variable:

OBJ: doing something
empty(OBJ):   false
OBJ == null:  false
OBJ === null: false

Sure, one should/could use "static calls" - like MethodsOnly::doSomething() - in this case (class without member vars), but we discovered this when migrating a project from PHP3 to PHP4 
.. and, anyway, shouldn't an existing object behave the same wether it has member variables or not? ;)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-11 06:05 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 17:01:30 2024 UTC