Possible bug in Object definition -- Fwd: [PHP-NOTES] note 12009 added to language.oop.php

From: Date: Sun, 18 Mar 2001 08:19:30 +0000
Subject: Possible bug in Object definition -- Fwd: [PHP-NOTES] note 12009 added to language.oop.php
Groups: php.dev 
Request: Send a blank email to php-dev+get-49272@lists.php.net to get a copy of this message
This is a strange behavior. If the original class have no predefined variables, then if the object's constructor does no assignment of its own, the resulting object compares to null, e.g. class foo { var $bar; function foo() { // do nothing } } $o = new foo(); if ($o == null) echo "boom!"; if (empty($o)) echo " zap!"; Outputs "boom! zap!", even when the object was created. Are we assuming than an object w/ no defined member vars is a null object? Not sure that is the expected behavior, but I might be wrong. Adding a predefined var in the class definition or setting one in the constructor, "fixes" the problem. Tested it w/ PHP 4.0.4pl1 and latest PHP from CVS (both compiled as stand alone executables) --- php-general@lists.php.net wrote: > Date: 18 Mar 2001 05:33:38 -0000 > To: php-notes@lists.php.net > From: php-general@lists.php.net > Subject: [PHP-NOTES] note 12009 added to > language.oop.php > > I wondered why the "new" assignments in these > examples were never tested for success --- ie. > if(!($var = new Cart())) echo "failure"; > > Now I know (at least for PHP4.0.4pl1). > > The test ALWAYS fails unless the constructor of the > class does a local member variable assignment. > > This I don't like. Could someone please explain to > me why this is a "good thing"? > > http://www.php.net/manual/en/language.oop.php > > > -- > PHP Notes Mailing List (http://www.php.net/) > To unsubscribe, e-mail: > php-notes-unsubscribe@lists.php.net > For additional commands, e-mail: > php-notes-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > ===== --- Jesus M. Castagnetto <jmcastagnetto@php.net> __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/

« previous php.dev (#49272) next »