|  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
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-10-15 17:29 UTC] sunco007 at hotmail dot com
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" ?> 
		     <nota> <url><![CDATA[opinion.php?id=16619&extra=m]]></url> <plaza>MZT</plaza> </nota> 
$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


Add a Patch

Pull Requests

Add a Pull Request


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

 $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: Mon Jul 15 07:01:28 2024 UTC