php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51525 Getting a node with a - in it
Submitted: 2010-04-10 03:56 UTC Modified: 2010-04-10 05:12 UTC
From: martin at aarhof dot eu Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.13 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: martin at aarhof dot eu
New email:
PHP Version: OS:

 

 [2010-04-10 03:56 UTC] martin at aarhof dot eu
Description:
------------
If a XML node have a - in it you can't get the data from it
<display-name>

echo $channel->display-name;
Notice: Use of undefined constant name - assumed 'name'

Test script:
---------------
<?xml version="1.0" encoding="UTF-8" ?>
<tv generator-info-name="www.ontv.dk/xmltv">
  <channel id="www.ontv.dk/tv/1">
    <display-name lang="dk">DR1 DK</display-name>
  </channel>
</tv>

$xml = simplexml_load_string($xml);
$channels = $this->xml->xpath('//channel');
foreach($channels AS $channel) {
  echo $channel->display-name;
}

Expected result:
----------------
DR1 DK

Actual result:
--------------
Notice: Use of undefined constant name - assumed 'name'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-10 04:12 UTC] martin at aarhof dot eu
-Type: Bug +Type: Feature/Change Request
 [2010-04-10 04:12 UTC] martin at aarhof dot eu
Solution is
echo $channel->{"display-name"};

Could this be fixed so you dont need the {} ?
 [2010-04-10 05:12 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-04-10 05:12 UTC] aharvey@php.net
Given that - already has another meaning in PHP, no, not really.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 23:01:27 2024 UTC