Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18392 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69375 invoked by uid 1010); 24 Aug 2005 23:31:16 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 69360 invoked from network); 24 Aug 2005 23:31:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Aug 2005 23:31:16 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:57361] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 5C/D2-28235-3430D034 for ; Wed, 24 Aug 2005 19:31:16 -0400 Received: (qmail 16579 invoked from network); 24 Aug 2005 23:31:11 -0000 Received: from localhost (HELO ANDI-NOTEBOOK.zend.com) (127.0.0.1) by localhost with SMTP; 24 Aug 2005 23:31:11 -0000 Message-ID: <6.2.3.4.2.20050824163046.05e01330@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.3.4 Date: Wed, 24 Aug 2005 16:31:08 -0700 To: Rasmus Lerdorf ,internals Cc: Stanislav Malyshev In-Reply-To: <430CEA87.7040805@lerdorf.com> References: <430CEA87.7040805@lerdorf.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] Schroedinger Objects From: andi@zend.com (Andi Gutmans) Yep I think that's a good point. Checking for cast is the right thing IMO. At 02:45 PM 8/24/2005, Rasmus Lerdorf wrote: >As per bug #34199 and as Rob points out, if($obj) and if(!$obj) are >handled by different opcodes and these two opcodes are inconsistent in >whether they call an object's cast_object handler. > >if($obj) results in a ZEND_JMPZ_SPEC_CV_HANDLER which calls >i_zend_is_true() which always return true for objects, no matter what >(ignore compatibility mode here) because of this code in zend_execute.h: > > case IS_OBJECT: > if(IS_ZEND_STD_OBJECT(*op)) { > TSRMLS_FETCH(); > if(EG(ze1_compatibility_mode)) { > result = (zend_hash_num_elements(Z_OBJPROP_P(op))?1:0); > } else { > result = 1; > } > } else { > result = 1; > } > break; > >if(!$obj) results in a which calls convert_to_boolean() which in turn >calls convert_object_to_type() which has: > >if (Z_OBJ_HT_P(op)->cast_object) { > > if (Z_OBJ_HT_P(op)->cast_object(op, op, ctype, 1 TSRMLS_CC) == >SUCCESS) { > op->type = ctype; > > } > >This means that any object which actually implements a cast_object >handler that returns false under some condition will be broken. The >simple example is: > > $a = simplexml_load_string(''); > if($a && !$a) echo "BUG!"; > >I think we need to fix i_zend_is_true's IS_OBJECT case to check to see >if the object has a cast_object handler and call it or just call >convert_to_boolean() there. Or we need to clean this up and not have >such different codepaths for these two cases. > >-Rasmus > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php