Re: Handling SimpleXMLElements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- From: "Jochem Maas" <jochem@xxxxxxxxxxxxx>


I'm guessing you have php5.0.x running - you really want a php5.1.x

PhpInfo reports it's 5.2.0 so I'm covered there.

version if your going to use XML - it will avoid *alot* headaches with
regarding to using var_dump() (or print_r() or even echo) to figure out
what the simpleXML objects are/contain.

Satyam wrote:
I have a problem trying to handle SimpleXml objects.  Though I can manage
some workaround the problem, I would like to understand it better.


....

cell.
Function dump() just does a var_dump() of whatever is given in the first
argument within a <pre> tag and uses the second argument as a heading,
surrounded by dashes.  In this case I copied the expression of what I am
dumping as the title (within single quotes so it does not expand).

 foreach($row as $cell) {
   dump($cell,'$cell);
   dump($cell->p,'$cell->p');
   dump((array)$cell->p,'(array)$cell->p');
   dump($cell->p[1],'$cell->p[1]');
  }

The section in question is shown below.  Though $cell is shown as a
SimpleXMLElement containing one 'p' property which contains an array of two
elements:
----------------------------$cell-----------------
object(SimpleXMLElement)#8 (1) {
 ["p"]=>
 array(2) {
   [0]=>
   string(12) "Indian Rupee"
   [1]=>
   string(8) "Ngultrum"
 }
}


If I dump that 'p' element, I don't get an array but an object with just
one element, the first value in the array
----------------------------$cell->p-----------------
object(SimpleXMLElement)#7 (1) {
 [0]=>
 string(12) "Indian Rupee"
}


If I typecast it to an array, I still get a single element
----------------------------(array)$cell->p-----------------
array(1) {
 [0]=>
 string(12) "Indian Rupee"
}

Nevertheless, if I explicitly index into the 'p' element, without even
typecasting it into an array, the second element is there.
----------------------------$cell->p[1]-----------------
object(SimpleXMLElement)#10 (1) {
 [0]=>
 string(8) "Ngultrum"
}


So, now you see it, now you don't, or do you?  What's happening?

Satyam



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux