Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97555 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61575 invoked from network); 7 Jan 2017 16:26:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jan 2017 16:26:42 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wm0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:35807] helo=mail-wm0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/C2-37836-1C611785 for ; Sat, 07 Jan 2017 11:26:41 -0500 Received: by mail-wm0-f43.google.com with SMTP id a197so57508106wmd.0 for ; Sat, 07 Jan 2017 08:26:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=gB+LmfDbaNQ06z2NiwFp7SSl5pex/luFc1fxiYft04c=; b=ZNNRDcg8i6soOT+lWnepbwmN+5YWXG5g028ia6Fu3zHQu9rdHT61RYxkvQqOriG9TO NxzVpCNp7iLdNXAOFV2uzZ5jeIbt8QLJ+5OXWVyLw5Kb21O7LVwhfIVWe95pRP2b3kVc Uq1AK7Ttf//Ky+A52seJz641sFJ2n3nz4TEdJPnv1kD+4I5LvU3RPkOsqjZU9BClhnm9 SwdR7OmkmQhmvH3Y7nI+00pl5UF5bYvQA4LElxxbn1AWnB4ERkJY1lLcmN7MHMR7WpoQ UuadGwupksH+lySb0Wm8TAP0PBbrPMHMqzCZJxdRxCFqADz/TPiAd8HAG0WKJ2JKQd5j OToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=gB+LmfDbaNQ06z2NiwFp7SSl5pex/luFc1fxiYft04c=; b=fHM/cGvhnjvO+TNZC7b1Kyac3EMyJYpZfl0haDciPvpdYBpCbErP9PgWM4A355P8lC wmihuYot7YXW7B2DIEMZPJNJp/uWckpidJ9qXzRIr1vbeYviB4Fsuc6ELDJXEQXZ54v2 SVzwfN9btvctfL4hAVwpA4C286PNUy1NVqRNkvLxp0U+O0G+ihhqJQsdySMFYIRoRi+n prBP7VWLcE2HYuLWtUYDj1tKxSVdbX6X9JhLKMSDSS75XYugipMnXOyk6hFBZKYsB8Fg GDZsv86wl+fpPhFnsIA7TIEbJuAqKtaYjbJ1K1vv9ernvwdPSHMeYupAi18drvuKdBzg FJVg== X-Gm-Message-State: AIkVDXIlLfHp4hizm4ZyV3R7uEvcNA4cjiCeI0cEYHIA9VcPwL9FfDBhmkgRG2DZliii5Q== X-Received: by 10.28.169.68 with SMTP id s65mr1557581wme.71.1483806397643; Sat, 07 Jan 2017 08:26:37 -0800 (PST) Received: from ?IPv6:2a00:23c4:4bd2:6e00:19e9:e99a:a646:76a2? ([2a00:23c4:4bd2:6e00:19e9:e99a:a646:76a2]) by smtp.googlemail.com with ESMTPSA id f67sm9115740wmd.13.2017.01.07.08.26.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Jan 2017 08:26:36 -0800 (PST) To: internals@lists.php.net References: Message-ID: <8e8f1cf4-a698-63b0-71a6-84daff20fdf2@gmail.com> Date: Sat, 7 Jan 2017 16:26:36 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SimpleXML's atXPath method From: rowan.collins@gmail.com (Rowan Collins) 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]