Bug #66277 [Nab]: Unable to compare two strings that should be equal
| From: | requinix@php.net | Date: | Thu, 12 Dec 2013 19:13:22 +0000 |
| Subject: | Bug #66277 [Nab]: Unable to compare two strings that should be equal | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183273@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66277&edit=1
ID: 66277
Updated by: requinix@php.net
Reported by: wmcgee at driverpipeline dot com
Summary: Unable to compare two strings that should be equal
Status: Not a bug
Type: Bug
Package: Strings related
Operating System: Windows Server 2012 R2
PHP Version: 5.5.3
Block user comment: N
Private report: N
New Comment:
My first instinct would be to use special handling for specific classes, such as Exception, and
get_object_vars() for the rest.
If you'd like more ideas or suggestions then check out a mailing list or forum.
http://www.php.net/support.php
Previous Comments:
------------------------------------------------------------------------
[2013-12-12 19:07:38] wmcgee at driverpipeline dot com
The purpose of this page is to expose as much information related to any error that may occur in XML
format to my C# windows service that is making the calls.
I made a C# windows service to make HttpWebRequests to my PHP server on a specified schedule based
on certain OS/Hardware parameters for instance if a Hard Drive starts getting full it will call a
script to remove older records etc. I wanted to find a way if an error occurs in my PHP script to
get as much information about the error to my service so it can log it in the windows event log
but my the XML returned was showing that Exceptiontrace or really "\0Exception\0trace" was
malformed.
Thanks for your help with this, After doing a little research would just running $key =
preg_replace( '/[^[:print:]]/', '',$key); work for removing all hidden
characters? or would you recommend completely changing the way I've got it set up
------------------------------------------------------------------------
[2013-12-12 18:49:59] requinix@php.net
When you treat objects as arrays, PHP mangles the names of protected and private members - it's
not like you're supposed to have access to them anyways. Private members are mangled to
"\0(class)\0(name)" and protected members to "\0*\0(name)".
Your code needs
$test = "\0Exception\0trace";
to match correctly.
I don't know the true purpose of your script nor what all obj2xml() needs to expose in the XML
but you should probably be using get_object_vars [http://www.php.net/get-object-vars] instead of
treating objects as arrays (like you're doing with the while/list/each). Such as
function obj2xml($v, $indent='') {
if (is_object($v)) { $v = get_object_vars($v); }
However it won't expose to you members you shouldn't have access to; calling it from
outside the class will only give you the public members, and Exception does not have any.
------------------------------------------------------------------------
[2013-12-12 16:02:23] wmcgee at driverpipeline dot com
Changed Email
And PHP version to 5.5.3
------------------------------------------------------------------------
[2013-12-12 15:56:41] wmcgee at driverpipeline dot com
Description:
------------
Server: Windows Server 2012 R2
Web Server: IIS 8.5
I am having an issue comparing two strings inside an IF statement. When I use var_dump to print out
both string values this is what I get:
string(16) "Exceptiontrace"
string(14) "Exceptiontrace"
As far as I can tell they both equal the same value but for some reason the top one is equal to
string(16) instead of 14 as would be expected. The value is generated by calling get_defined_vars()
after catching an exception.
NOTE: $x may need to be adjusted to target the Exceptiontrace object
Test script:
---------------
Source View: http://www.wil-tec.com/src/test.html
Actual Script: http://www.wil-tec.com/src/test.php
Expected result:
----------------
I expect php to execute either A or B, but not C
A. die("I should be only Value Printed"); Line: 36
B. die("Or If that doesnt work I should be."); Line: 37
C. die('But i actually am the last and key does = "' . $key . '"');
Line: 46
Actual result:
--------------
php ends up executing C and the output looks like:
[START OUTPUT]
string(16) "Exceptiontrace"
string(14) "Exceptiontrace"
But i actually am the last and key does = "Exceptiontrace"
[END OUTPUT]
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66277&edit=1