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('<foo><a><b><b1>b1val</b1><b2>b2val</b2></b></a></foo>
>> ');
>> $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:[EMAIL PROTECTED]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to