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]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php