php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46306 Can't set a variable that i get from Xml
Submitted: 2008-10-15 17:29 UTC Modified: 2008-10-16 06:11 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: sunco007 at hotmail dot com Assigned:
Status: Wont fix Package: SimpleXML related
PHP Version: 5.2.6 OS: Vista Business
Private report: No CVE-ID: None
 [2008-10-15 17:29 UTC] sunco007 at hotmail dot com
Description:
------------
I create a Xml file and when i want to read some values it just return a blank value. I you do an echo to every value works fine, but when you put all togheter is when it fails

The same if you read directly from a file or from a var (simplexml_load_file or simplexml_load_string)

Reproduce code:
---------------
<?
$values = '<?xml version="1.0" encoding="ISO-8859-1" ?> 
           <root> 
		     <nota> <url><![CDATA[opinion.php?id=16619&extra=m]]></url> <plaza>MZT</plaza> </nota> 
		   </root>';
$xml = simplexml_load_string($values);

foreach ($xml->nota as $datos) {
  // work
  echo "-".$datos->plaza."-<br>";
  // work
  echo "-".$datos->url."-<br>";
  
  // put together
  $malecon_link[$datos->plaza] = $datos->url;
  // don't work
  echo "-".$malecon_link[$datos->plaza]."-<br>";
}
?>

Expected result:
----------------
$malecon_link[$datos->plaza] must return the value, in this case the url

Actual result:
--------------
Return a blank value

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-16 06:11 UTC] chregu@php.net
Due to the way simplexml works, you have to cast that to a string. Just 
write

 $malecon_link[(string) $datos->plaza] = $datos->url;

and then it does what you expect
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 16:01:33 2024 UTC