|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
42 - 11 = ?
Subscribe to this entry?

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

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="">
  <channel id="">
    <display-name lang="dk">DR1 DK</display-name>

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

Expected result:

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


Add a Patch

Pull Requests

Add a Pull Request


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]
-Status: Open +Status: Bogus
 [2010-04-10 05:12 UTC]
Given that - already has another meaning in PHP, no, not really.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Apr 01 08:03:37 2023 UTC