Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:8406 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34904 invoked by uid 1010); 6 Mar 2004 14:58:21 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 34880 invoked from network); 6 Mar 2004 14:58:21 -0000 Received: from unknown (HELO moutng.kundenserver.de) (212.227.126.189) by pb1.pair.com with SMTP; 6 Mar 2004 14:58:21 -0000 Received: from [212.227.126.207] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1AzdFt-0007iV-00 for internals@lists.php.net; Sat, 06 Mar 2004 15:58:21 +0100 Received: from [80.139.5.208] (helo=[80.139.5.208]) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1AzdFt-0004p6-00 for internals@lists.php.net; Sat, 06 Mar 2004 15:58:21 +0100 To: internals@lists.php.net In-Reply-To: <5.1.0.14.2.20040304140729.02098198@127.0.0.1> References: <1078074613.1440.9.camel@localhost> <1078074613.1440.9.camel@localhost> <5.1.0.14.2.20040304140729.02098198@127.0.0.1> Content-Type: text/plain Message-ID: <1078584828.266.48.camel@localhost> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.4 Date: Sat, 06 Mar 2004 15:53:49 +0100 Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:e958292ea7b1c44e51b2b9ca0a9da460 Subject: Re: [PHP-DEV] BC break: $o= new stdclass; empty($o) From: thekid@thekid.de (Timm Friebe) On Thu, 2004-03-04 at 13:10, Andi Gutmans wrote: > Hey, Hi, > The reason for this behavior is that in PHP 3 and 4, objects were treated > very much like arrays (this is the main reason for redesigning the object > model for PHP 5). > I don't think that the old behavior is correct and an empty should always > return true (i.e. empty($var) should return true if the variable is NULL > and false if $var is an object). to clarify: Maybe I was misusing PHP by doing the following: class null { function null() { } function __call($name, $args) { throw(new NullPointerException('Method.invokation('.$name.')')); } function __set($name, $value) { throw(new NullPointerException('Property.write('.$name.')')); } function __get($name) { throw(new NullPointerException('Property.read('.$name.')')); } } class registry { public static $null; } registry::$null= new null(); class ClassType { function forName($name) { // ... abbreviated ... return new ClassType($name); } function getConstructor() { if (!$this->hasConstructor()) return registry::$null; return $this->constructor; } } $i= ClassType::forName($class)->getConstructor()->newInstance(); What I am doing here is fatal error prevention. To come to my point: The following statement: if (ClassType::forName($class)->getConstructor()) { // ... } would now always evaluate to (bool)true. In PHP4 (where, of course, the syntax need be a bit different) the above statement would evaluate to (bool)false due to the "emptiness" of the null object. I know this is kind of hacky but was a nice way of being able to have a way of implementing a "Fatal error: Call to a member function of a non-object"-safe "NULL" *and* being able to check for it using boolean operators. > I don't think we should by default support the PHP 4 behavior because it's > just not right. What I suggest is to either break BC completely or support > the old behavior in compatibility mode. > What option do you prefer? I saw you already committed a patch for the latter option (return 0 in compat mode). I'm not sure whether this affects a lot of users, and as noone has commented on it, I guess PHP5 will get away with this break:) I'll just have to find a workaround if you insist the PHP4 behaviour is broken:) - Timm