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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sunco007 at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Sat Apr 20 00:01:27 2024 UTC