Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30414 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92514 invoked by uid 1010); 2 Jul 2007 20:41:41 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 92499 invoked from network); 2 Jul 2007 20:41:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2007 20:41:41 -0000 X-Host-Fingerprint: 207.126.230.225 nat-dip4.corp.yahoo.com Received: from [207.126.230.225] ([207.126.230.225:2169] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/32-06865-30369864 for ; Mon, 02 Jul 2007 16:41:40 -0400 Message-ID: <4F.32.06865.30369864@pb1.pair.com> To: internals@lists.php.net Date: Mon, 02 Jul 2007 13:41:36 -0700 User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070004000208060805060003" X-Posted-By: 207.126.230.225 Subject: SimpleXML emptiness From: pollita@php.net (Sara Golemon) --------------070004000208060805060003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------070004000208060805060003 Content-Type: text/plain; name="simplexml-empty.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="simplexml-empty.txt" 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; + } } } } --------------070004000208060805060003--