Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7135 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51685 invoked by uid 1010); 16 Jan 2004 09:27:32 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 51609 invoked from network); 16 Jan 2004 09:27:32 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 16 Jan 2004 09:27:32 -0000 Received: from [192.168.1.100] (p508EB219.dip.t-dialin.net [80.142.178.25]) by shiva.mind.de (Postfix) with ESMTP id 7C46597B66; Fri, 16 Jan 2004 10:27:25 +0100 (CET) Date: Fri, 16 Jan 2004 10:25:31 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <94-2136388359.20040116102531@marcus-boerger.de> To: Adam Maccabee Trachtenberg Cc: Rob Richards , Marcus Boerger , internals@lists.php.net In-Reply-To: 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 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] SimpleXML: Moving Forward From: helly@php.net (Marcus Boerger) Hello Adam, Thursday, January 15, 2004, 6:01:58 PM, you wrote: > 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.) Just a node: The thing you saw required SXE objects implementing interface RecursiveIterator{reset(), hasMore(), key(), current(), next(), hasChildren(), getChildren()} >> 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. That's exactly why dimity tried to implement $obj->node[0]. And i guess this is vital to the extension. > 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 > } To achieve that the property ready handler would have to return an array or iterator class always. That's all that needs to be changed. Unfortunatley this would be a major change of functionality so feel free to drop proeprty handling completley. > 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); >> } >> } I guess it can be done by simply fixing the refcounting. So why not start some work/analysis instead of mucking around? The least bit you could do is writing some test files under test subdirectory. > Nasty crashes are bad. :) > -adam -- Best regards, Marcus mailto:helly@php.net