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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2023 The PHP Group
All rights reserved.
Last updated: Sun Feb 05 02:05:48 2023 UTC