Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97557 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68917 invoked from network); 7 Jan 2017 17:01:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2017 17:01:14 -0000 Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 74.125.82.51 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:37809] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/44-37836-7DE11785 for ; Sat, 07 Jan 2017 12:01:12 -0500 Received: by mail-wm0-f51.google.com with SMTP id t79so68208076wmt.0 for ; Sat, 07 Jan 2017 09:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pthreads-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fUhsxhLLZbrk+m1rL0nZDghsQGXf+ysProZQmCoXOlk=; b=kMnGcI1+gCltUkwTFgBtt1twMB4N8JSIlHq9wXfn8SrYm244Gz9py7NJ22fU+pYmht OJXVE+vjUW9CEduAsOlntZj5n6dd457VtlslmoqjzAvl6pOe7BEfmzzkiDAtUlzO5afZ 4uvuHdifxN8wjnx0bq2pJS5iamb98BjlU0+yKa0N96/ElYQUmKevmLrn5mYZwV4X/8Cr JER3r+3khcSfjDk0QeuCcch7nRuv2b0XJmCSU7iXD2DM/9pc3gwcoYXlpNvb/+ae8Ddh I927q698MNWVC40echTz+IXz1pQVqzWNu78q+Zv6fh3VAZVzdWsr56MIhf9hmggIhIA3 dNyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fUhsxhLLZbrk+m1rL0nZDghsQGXf+ysProZQmCoXOlk=; b=WoAYgJaSpNJ+NnWMfnJeZgA9pNShuT8bCHTyYPx5vIx2WHjDnptGum4NawTjPgh+tv o802IElaM8p/7S9lGNxsEc6hkWvbtYKDmwIa0egWB/mTb2Y51b2f+cW8iKdjazlEDPr2 OUyx6GmsKXYtm3J3T2ygQPhJaEdVWwhM6UVBSuyiSBMCrfISX57kEC1jjj3Gr5fAjrq5 eQOt5uRML2oOUbT1jbX2glxLw2eTYa7Zuql2g4S3+DszoW/I93hHgGPAua/zaWAoGORa 4WDcGzDnIjkk02n3RZgtfA3oIFGtGqA3eGqhN65TeDGPQgsE41J18r43XR9PGBT2Bei8 XshA== X-Gm-Message-State: AIkVDXKYfG41m8ZgAHJSjilDjX7DvKc78w+N+wcwzS1RdHGiyLxuY/ptCWVSWxuSUAYIf9LSjclWVtzrlLsw1g== X-Received: by 10.223.145.198 with SMTP id 64mr5666869wri.101.1483808464119; Sat, 07 Jan 2017 09:01:04 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.176.4 with HTTP; Sat, 7 Jan 2017 09:01:03 -0800 (PST) X-Originating-IP: [86.178.168.203] In-Reply-To: <8e8f1cf4-a698-63b0-71a6-84daff20fdf2@gmail.com> References: <8e8f1cf4-a698-63b0-71a6-84daff20fdf2@gmail.com> Date: Sat, 7 Jan 2017 17:01:03 +0000 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=94eb2c0d24a06b499305458414ba Subject: Re: [PHP-DEV] SimpleXML's atXPath method From: pthreads@pthreads.org (Joe Watkins) --94eb2c0d24a06b499305458414ba Content-Type: text/plain; charset=UTF-8 Evening Rowan, I must protest: It is wasteful, unclear, and generally nasty, to create, return, and manipulate an array if you are only ever going to reference one element in code. It is quite normal to know the structure of a document ahead of time, and this would allow you to write more succinct and less wasteful code. It would appear valuable to me ... I'm not in love with the name of the thing, but the basic idea appears valuable. Cheers Joe On Sat, Jan 7, 2017 at 4:26 PM, Rowan Collins wrote: > On 06/01/2017 14:03, Willian Veiga wrote: > >> Hello, >> >> What do you think about a new method, called atXPath, that would return a >> single SimpleXMLElement? >> >> Details: >> >> https://github.com/php/php-src/pull/1717 >> https://bugs.php.net/bug.php?id=45201 >> >> Thank you, Willian. >> >> > My first thought on this was "what does the 'at' mean?" I see now that > it's copied from another library, but "atXPath" really doesn't make me > think "xpath for single element". > > My second thought is that this feature is actually no longer needed. The > original feature request was to avoid the need for an intermediate variable > when you know you're getting back one result: > > $firstresult=$xml->xpath('element[@called="XYZ"]'); > $secondresult=$firstresult[0]->xpath('child[@named="ABC"]'); > $finalresult=$secondresult[0]; > > But in all versions of PHP since 5.4 you can simply add the [0] on the end > of the function call anyway: > > $finalresult=$xml->xpath('element[@called="XYZ"]')[0]->xpath > ('child[@named="ABC"]')[0]; > > Like the original proposal for an extra parameter, this extends to > selecting whichever result you want, as long as you're sure it exists. > > Example: https://3v4l.org/1k9rk > > If you don't know for sure that there will be enough results, then > chaining will give an error either way, and this isn't really any different > from any other method that might or might not return the expected object. > > Regards, > > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --94eb2c0d24a06b499305458414ba--