Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7127 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42775 invoked by uid 1010); 15 Jan 2004 17:01:59 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 42699 invoked from network); 15 Jan 2004 17:01:59 -0000 Received: from unknown (HELO miranda.org) (209.58.150.153) by pb1.pair.com with SMTP; 15 Jan 2004 17:01:59 -0000 Received: (qmail 13975 invoked by uid 546); 15 Jan 2004 17:01:58 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 15 Jan 2004 17:01:58 -0000 Date: Thu, 15 Jan 2004 12:01:58 -0500 (EST) X-X-Sender: adam@miranda.org To: Rob Richards cc: Marcus Boerger , internals@lists.php.net In-Reply-To: <026101c3db83$1e80c4a0$f7dea8c0@cyberware.local> Message-ID: References: <562031508046.20040114230741@marcus-boerger.de> <19800119111039.GC2178@bumblebury.com> <1572071705312.20040115101738@marcus-boerger.de> <026101c3db83$1e80c4a0$f7dea8c0@cyberware.local> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] SimpleXML: Moving Forward From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) On Thu, 15 Jan 2004, Rob Richards wrote: > Ignore the user space issue for right now as I dont go into that at all. I > dont see iterators as being worthless, however there is a behavior clash > between the iterators and the arrays. I really like Iterators, so I'd like to see this ironed out. Based on what I've seen from Marcus at ApacheCon you can do really cool stuff with them and I don't think there's any reason to delete them if they can be implemented consistently alongside the rest of the extension. (Which I'm sure they can be.) > When fetching properties returning arrays for multiple elements and > returning a single sxe object for single elements (as the single sxe object > will iterate the children of the returned object). A foreach will give > different results depending upon which is returned. > $a = $foo->a; > foreach($a->b as $b) { > ... > } > > imo, the behavior should be the same regardless of what is returned. This > pretty much means generalizing things to use either arrays or iterators. This is one of my problems because even if you know a document's Schema, you can still run into instances where a node may have 0, 1, or more subelements of the same name. I know this has been discussed before. (I think I remember George being involved, but I can't remember who else.) The current solution is to do: if (is_set($foo->a)) { if (is_array($foo->a)) { foreach($foo->a as $a) { // blah with $a } } else { // blah with $foo->a } } It would be a "Real Good Thing" (tm), if that could be turned into this: foreach($foo->a as $a) { // blah $a } If this can be done using Iterators, I see it as a strongly compelling reason to use them. I think this is a clear-cut win in terms of programming simplicity (and I should know since I've got over 2,000 lines of code that's either the little dance above or a variation of it). > However to implement something like above as well as to implement iterators > in sxe at all, they are going to need to point to the node proxies rather > than to the libxml nodes themselves otherwise it can be made to segfault (as > is the case today): > $foo = > simplexml_load_string('b1valb2val > '); > $a = $foo->a; > foreach($a as $b) { > foreach($b as $subb) { > print $subb."\n"; > unset($foo->a); > } > } Nasty crashes are bad. :) -adam -- adam@trachtenberg.com author of o'reilly's php cookbook avoid the holiday rush, buy your copy today!