Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29655 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88347 invoked by uid 1010); 22 May 2007 09:50:28 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 88331 invoked from network); 22 May 2007 09:50:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 May 2007 09:50:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=christian.stocker@liip.ch; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=christian.stocker@liip.ch; sender-id=unknown Received-SPF: error (pb1.pair.com: domain liip.ch from 194.50.176.140 cause and error) X-PHP-List-Original-Sender: christian.stocker@liip.ch X-Host-Fingerprint: 194.50.176.140 zimbra.liip.ch Received: from [194.50.176.140] ([194.50.176.140:52487] helo=zimbra.liip.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/34-46001-1ECB2564 for ; Tue, 22 May 2007 05:50:27 -0400 Received: from localhost (zimbra [127.0.0.1]) by zimbra.liip.ch (Postfix) with ESMTP id 25FD421D52BE; Tue, 22 May 2007 11:50:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at X-Spam-Score: -2.414 X-Spam-Level: X-Spam-Status: No, score=-2.414 tagged_above=-10 required=6.6 tests=[AWL=0.050, BAYES_00=-2.599, FORGED_RCVD_HELO=0.135] Received: from zimbra.liip.ch ([127.0.0.1]) by localhost (zimbra.liip.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9juRyUw7b6KV; Tue, 22 May 2007 11:50:22 +0200 (CEST) Received: from pr.local (office-zh.liip.ch [91.192.102.250]) by zimbra.liip.ch (Postfix) with ESMTP id CAB4121D4077; Tue, 22 May 2007 11:50:21 +0200 (CEST) Message-ID: <4652BCDB.1040900@liip.ch> Date: Tue, 22 May 2007 11:50:19 +0200 Organization: Liip AG User-Agent: Thunderbird 2.0.0.0 (Macintosh/20070326) MIME-Version: 1.0 To: Vesselin Kenashkov CC: internals@lists.php.net References: <261daaa10705220123m41b254a6p6b44d21b29ad1d4c@mail.gmail.com> In-Reply-To: <261daaa10705220123m41b254a6p6b44d21b29ad1d4c@mail.gmail.com> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] unexpected behaviour in SimpleXML (php 5.2.2) From: christian.stocker@liip.ch (Christian Stocker) I can't answer on your first topic, but the second: On 22.5.2007 10:23 Uhr, Vesselin Kenashkov wrote: > Hello everybody, > Issue #2: > Xpath on nodes. > Let we have the example: > ----------------- > $str = > ''; > > > $x = new SimpleXMLElement($str); > > $r1 = $x->xpath('/*'); > print $r1[0]->getName();//prints rootnode > > $r2 = $x->level1_node1[0]->xpath('/*'); > print $r2[0]->getName();//prints rootnode > > $z = clone $x->level1_node1[0]; > $r3 = $z->xpath('/*'); > print $r3[0]->getName();//prints rootnode > > //print $z->getName();//ok > ------------------ That's how it works also in ext/dom (and IMHO as it's supposed to work), but the "workaround" is easy: $r2 = $z->xpath('./*'); works as you would expect it. chregu > I personally think that the xpath must be evaluated against the node which > method is called, not always against the rootnode. > So in the second example I would expect it to return level1_node1, and > especially in the thirds example. > Even in the third example the xpath is evaluated against the original XML > structure, not the subnode (level1_node1). > I think this is incorrect and leads to a confusion - for example we can > pass > a node to a function like: > -------- > function do_something($node) > { > //print $node->getName();//prints correct - the name of the supplied > node - level1_node1 > $r1 = $node->xpath('/*'); > print $r1[0]->getName(); > } > > do_something(clone $x->level1_node1[0]); > -------- > The do_something function is not aware at all about the full xml structure > and one could think that the expression will be evaluated just against the > supplied node, but it is not that the case. > > Please give your comments - do you find this functionality OK, is it a bug, > or I miss something. > > > Vesselin Kenashkov > -- christian stocker | Liip AG | schoeneggstrasse 5 | ch-8004 zurich phone +41 44 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.liip.ch/ | christian.stocker@liip.ch | GnuPG 0x5CE1DECB