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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC