Re: SimpleXML's atXPath method

From: Date: Sat, 07 Jan 2017 18:24:57 +0000
Subject: Re: SimpleXML's atXPath method
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-97561@lists.php.net to get a copy of this message
On 07/01/2017 17:01, Joe Watkins wrote:
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.
Meh, feels like a micro-optimisation to me, and "[0] to access first search result" seems pretty obvious, but fair enough if you disagree. I know development's not a zero-sum game, but there are plenty of things I'd add to the SimpleXML extension that aren't just aliases for things you can trivially do already. For instance, sticking with XPath usage, the fact that registerXPathNamespace() only affects the current element, so has to be re-run as you traverse: $sx->registerXPathNamespace('a', 'http://example.com'); $foo = $xml->xpath('//a:foo')[0]; // do something with $foo $foo->registerXPathNamespace('a', 'http://example.com'); // won't work without this $bar = $foo->xpath('./a:bar')[0]; That's a lot more intrusive than needing to add "[0]" next to a few method calls. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#97561) next »