#27413 [Bgs->Fbk]: SimpleXML text comparison
| From: | helly@php.net | Date: | Sun, 07 Mar 2004 15:15:14 +0000 |
| Subject: | #27413 [Bgs->Fbk]: SimpleXML text comparison | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-56036@lists.php.net to get a copy of this message | ||
ID: 27413
Updated by: helly@php.net
Reported By: rbro at hotmail dot com
-Status: Bogus
+Status: Feedback
Bug Type: XML related
Operating System: Linux
PHP Version: 5CVS-2004-02-26 (dev)
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2004-02-27 13:51:55] rbro at hotmail dot com
Thanks for your reply, but if that's the intended behavior (that
echo'ing the attribute prints it out as a string, but trying to compare
it doesn't work without a cast to a string), then the documentation
then needs to be updated. The 'Using attributes' example on
http://docs.php.net/en/ref.simplexml.html
says that what I'm trying to
do should work. That example then is invalid too.
------------------------------------------------------------------------
[2004-02-27 13:34:25] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
As Derick said, the explicit conversion is necessary because php tries
to convert the second argument to the first argument\'s type which is
an object. Generally it could work when you switch the order of
arguments but the explicit conversion makes it visible what you do.
------------------------------------------------------------------------
[2004-02-27 09:04:12] derick@php.net
If you cast to a string, it works:
if ((string) $sxe['a'] == '123')
I do think that should be necessary though.
------------------------------------------------------------------------
[2004-02-27 09:00:12] rbro at hotmail dot com
Yes, doing 'var_dump($sxe['a']);' gives:
object(simplexml_element)#2 (1) {
[0]=>
string(3) "123"
}
But then changing my if line to:
if ($sxe['a'][0] == '123')
doesn't work either.
How does one then compare an attribute to another value? The
documentation at http://docs.php.net/en/ref.simplexml.html
states that
my original if statement should work (the example under 'Using
attributes'). That example doesn't work locally either because of the
same issue on the switch statement used.
------------------------------------------------------------------------
[2004-02-27 02:16:45] sniper@php.net
Try doing a 'var_dump($sxe['a']);'...comparing string to an object
can't really be true in any case?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/27413
--
Edit this bug report at http://bugs.php.net/?id=27413&edit=1