Bug #66277 [Opn->Nab]: Unable to compare two strings that should be equal

From: Date: Thu, 12 Dec 2013 18:49:59 +0000
Subject: Bug #66277 [Opn->Nab]: Unable to compare two strings that should be equal
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183271@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: Open +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: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#183271) next »