|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33906 value comparsion doesn't work as expected
Submitted: 2005-07-28 16:07 UTC Modified: 2005-07-28 16:32 UTC
From: ray-chords at gmx dot net Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.0.4 OS: Debian Sarge
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.
Block user comment
Status: Assign to:
Bug Type:
From: ray-chords at gmx dot net
New email:
PHP Version: OS:


 [2005-07-28 16:07 UTC] ray-chords at gmx dot net
Intention was to compare a string value with an xml node value. But direct access to the value fails.

Reproduce code:
$xml_string = <<<EOD
<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
    <command default="yes"><id><![CDATA[li]]></id></command>

$xml = simplexml_load_string($xml_string);
$template = $xml->xpath('/document/command/id');
foreach ($template as $v) {
    $out = ($v->id == 'pwd') ? 'OK' : 'FALSE'; 
    print $out . "\n";

Expected result:
I'd expected an 'OK' in the last loop. But I always get 'FALSE'.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-28 16:23 UTC]
RTFM. You have to cast to string first.

 [2005-07-28 16:32 UTC] ray-chords at gmx dot net
no, casting to string has no effect.

As I find out, a SimpleXMLElement including just one node with only one value must be called directly.

change line 17: $out = ($v->id == 'pwd') ? 'OK' : 'FALSE'; 
to:             $out = ($v == 'pwd') ? 'OK' : 'FALSE';

and it works as expected.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 21:01:28 2024 UTC