Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14929 invoked by uid 1010); 3 Jul 2007 14:37:49 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 14914 invoked from network); 3 Jul 2007 14:37:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jul 2007 14:37:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.coallier@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.coallier@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.184.231 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: david.coallier@gmail.com X-Host-Fingerprint: 64.233.184.231 wr-out-0506.google.com Linux 2.4/2.6 Received: from [64.233.184.231] ([64.233.184.231:38005] helo=wr-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/46-41468-A3F5A864 for ; Tue, 03 Jul 2007 10:37:48 -0400 Received: by wr-out-0506.google.com with SMTP id 68so1232274wra for ; Tue, 03 Jul 2007 07:37:44 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=KNh25yJXf2G9JlzQiPBQjM8JgpjaKUmD7eZJ5zKu4a6oTokADP1ipBPkulfAQ751meLOUhKkY2017G5Z0V3CwSmB/aynpINJEoaP1DG9lnYQH0k64eM5InJsgiIrFOsLBE1d/t36RMWhcatOtoFc5y27lm25BHN1XyI/lhFjXa0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=RpK1oIY7QdfK9hOP4+K2u4gzt7YNovTuRFyHY4VcHxG7gh7C0aRxsaGh2x8Oa5C9Xu8YRWL13EakOvHDBjIaM+XZzGxdGpgtGinR8SdoA9X+DL1N0fGjbHaKQwYUuoXLQGWOWOjcidbtPtgDBwtyxzkBEBOzzzrrp6rfuOst6lk= Received: by 10.90.118.8 with SMTP id q8mr6168496agc.1183473464299; Tue, 03 Jul 2007 07:37:44 -0700 (PDT) Received: by 10.90.87.1 with HTTP; Tue, 3 Jul 2007 07:37:44 -0700 (PDT) Message-ID: Date: Tue, 3 Jul 2007 10:37:44 -0400 Sender: david.coallier@gmail.com To: "Sara Golemon" Cc: internals@lists.php.net In-Reply-To: <4F.32.06865.30369864@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4F.32.06865.30369864@pb1.pair.com> X-Google-Sender-Auth: e265c95611b156a9 Subject: Re: [PHP-DEV] SimpleXML emptiness From: davidc@php.net ("David Coallier") On 7/2/07, Sara Golemon wrote: > Currently, an empty check like the following returns false because > SimpleXML only checks for node existence in has_property. I'd like to > propose the attached patch to change this to look at the node's children > and apply PHP's emptiness rules to the content. > > $data = ' > > > 0 > foo > > '; > > $s = simplexml_load_string($data); > var_dump(empty($s->e1)); // Currently false > var_dump(empty($s->e2)); // Currently false > var_dump(empty($s->f1)); // False > var_dump(empty($s->x['eprop'])); // Currently false > var_dump(empty($s->x['fprop'])); // False > > Note that this patch only effects elements which only contains an empty > text node or only a text node with a literal "0". If the element > contains real children, then it's considered to be non-empty (even if > those children are in turn empty themselves). > > -Sara > > > Index: ext/simplexml/simplexml.c > =================================================================== > RCS file: /repository/php-src/ext/simplexml/simplexml.c,v > retrieving revision 1.151.2.23 > diff -u -p -r1.151.2.23 simplexml.c > --- ext/simplexml/simplexml.c 1 Jan 2007 09:40:27 -0000 1.151.2.23 > +++ ext/simplexml/simplexml.c 2 Jul 2007 20:30:05 -0000 > @@ -692,6 +692,11 @@ static int sxe_prop_dim_exists(zval *obj > attr = attr->next; > } > } > + if (exists && check_empty == 1 && > + (!attr->children || !attr->children->content || !attr->children->content[0] || !xmlStrcmp(attr->children->content, "0")) ) { > + /* Attribute with no content in it's text node */ > + exists = 0; > + } > } > > if (elements) { > @@ -714,6 +719,11 @@ static int sxe_prop_dim_exists(zval *obj > } > if (node) { > exists = 1; > + if (check_empty == 1 && > + (!node->children || (node->children->type == XML_TEXT_NODE && !node->children->next && > + (!node->children->content || !node->children->content[0] || !xmlStrcmp(node->children->content, "0")))) ) { > + exists = 0; > + } > } > } > } > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Tested it and makes perfect sense. -- David Coallier, Founder & Software Architect, Agora Production (http://agoraproduction.com) 51.42.06.70.18