php.net |  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:

<?php

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

$OBJ = new MethodsOnly();
$OBJ->doSomething();
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? ;)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-11 06:05 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC