php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57283 Interator failure
Submitted: 2006-10-06 06:55 UTC Modified: 2006-11-28 09:27 UTC
From: simonslaws at googlemail dot com Assigned:
Status: Not a bug Package: SCA_SDO (PECL)
PHP Version: 5.1.4 OS: XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: simonslaws at googlemail dot com
New email:
PHP Version: OS:

 

 [2006-10-06 06:55 UTC] simonslaws at googlemail dot com
Description:
------------
I am trying to us an iterator to iterator across an SDO many valued property. 

        $itemIterator = $rss->channel->item->getIterator();
        while ( $iterator->valid() && $item == null ) {
            if ($itemIterator->current()->title == $title ) {
                $item = $itemIterator->current();
            }
            $iterator->next();
        }

When running this I get: 

[Sun Oct 01 11:21:18 2006] [error] [client 127.0.0.1] PHP Fatal error:
Call to undefined method SDO_DataObjectList::getIterator() in
C:\\simon\\Projects\\Eclipse3.2\\ajax-rss\\sdoajax.php on line 70

Reproduce code:
---------------
With array.xsd
==============
    <complexType name="ArrayContainerType">
        <sequence>
            <element name="Array" type="string" minOccurs="1" maxOccurs="unbounded"/>
        </sequence>
    </complexType>
    
    <element name="ArrayContainer" type="tns:ArrayContainerType"/>
    
and code
========
<?php
$xmldas = SDO_DAS_XML::create('array.xsd');

$array_doc 		 = $xmldas->createDocument();
$array_container = $array_doc->getRootDataObject(); 

$array_container->Array[] = "arrayitem1";
$array_container->Array[] = "arrayitem2";
$array_container->Array[] = "arrayitem3";

$itemIterator = $array_container->getIterator();
        while ( $iterator->valid() && $item == null ) {
            echo "An Item ";
            print_r($itemIterator->current());
            $iterator->next();
        } 

?>

Expected result:
----------------
Print out the three elements of the array

Actual result:
--------------
The filename, directory name, or volume label syntax is incorrect.
PHP Fatal error:  Call to undefined method SDO_DataObjectImpl::getIterator() in
C:\simon\Projects\Eclipse3.2\phpscripts\peclx.php on line 11

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-28 09:27 UTC] cem@php.net
Thank you for taking the time to write to us, but this is not
a bug.

SDO_DataObject doesn't have a getIterator method. There are SPL classes which let you do this. You can use an IteratorIterator (really) to get a userland view into the iteration functions, for example:

    $iter = new IteratorIterator($do, 'SDO_DataObjectImpl');

(Note that you have to use the implementation class name, even though the SDO_DataObject interface does itself extend Traversable, but SPL wants the name of a concrete class.)

Once you have your iterator you can then do all the iterator operations on it: rewind(), key(), current(), next(), and valid().

A refinement would be to add an SDO_Iterator class (c.f. SimpleXMLIterator) as a subclass of IteratorIterator, which would work with all the Traversable SDO objects (DataObject, List, Sequence). This would implement getIterator() and look a bit nicer than the above. I'll put this on the wish list.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC