From: Operating system: WIN PHP version: 5.2.13 Package: Unknown/Other Function Bug Type: Bug Bug description:Bug in filter_var with SimpleXMLElement
Description: ------------ In 5.2.1 we always received the string 'png' in example 2. It seems that filter_var does not call the "__toString" (or something similar) Method at least for SimpleXMLElement objects. Example 3 is working correctly. Test script: --------------- class Benutzer { protected $name; public function __construct( $name ) { $this->name = $name; } public function __toString() { return $this->name; } } $benutzer = new Benutzer( 'TEST' ); $xmlstring = '<?xml version="1.0" encoding="iso-8859-1"?'.'><file uuid="samplefile_1234234646sdfsdf" name="openengine_logo" ext="png" status="released" action="update"> <meta> <attribute key="title" value="Download A"/> <attribute key="product_name" value="Product A"/> <attribute key="product_name" value="Product B"/> <attribute key="product_name" value="Product C"/> <attribute key="product_family" value="Product Family A"/> <attribute key="product_version" value="1.0"/> <attribute key="group_main" value="Group A"/> <attribute key="group_sub" value="Group B"/> <attribute key="document_type" value="Image"/> <attribute key="document_type" value="Video"/> <attribute key="document_type" value="Audio"/> <attribute key="language" value="en"/> <attribute key="language" value="de"/> <attribute key="description" value="This is a sample file"/> <attribute key="release_date" value="2003-06-04T12:30:17"/> </meta> <auth folder="YYY"/> <user id="XXX"/> </file>'; $xml = simplexml_load_string($xmlstring); echo "\n###################################################\n"; echo "Testing filter_var with SimpleXMLElement Object\n"; echo "\n###################################################\n"; echo "\nExample 1"; echo "\n----------------------------\n"; echo "DUMP XML Attribute\n\n"; echo "Output:\n"; echo $xml["ext"]; echo "\n----------------------------\n"; echo "\nExample 2"; echo "\n----------------------------\n"; echo "Output filter_var\n\n"; echo "Result:\n"; echo var_dump(filter_var($xml["ext"], FILTER_SANITIZE_STRING)); echo "\n\nPROBLEM: in former versions as 5.2.1 result has been 'png'"; echo "\n----------------------------\n"; echo "\nExample 3"; echo "\n----------------------------\n"; echo "Output filter_var with active type switching\n\n"; echo "Result:\n"; echo var_dump(filter_var((string) $xml["ext"], FILTER_SANITIZE_STRING)); echo "\n----------------------------\n"; echo "\nExample 4"; echo "\n----------------------------\n"; echo "Output user object with __toString Method\n\n"; echo "Result:\n"; echo var_dump(filter_var($benutzer, FILTER_SANITIZE_STRING)); echo "\n----------------------------\n"; Expected result: ---------------- ################################################### Testing filter_var with SimpleXMLElement Objects ################################################### Example 1 ---------------------------- DUMP XML Attribute Output: png ---------------------------- Example 2 ---------------------------- Output filter_var Result: string(3) "png" PROBLEM: in former versions as 5.2.1 result has been 'png' ---------------------------- Example 3 ---------------------------- Output filter_var with active type switching Result: string(3) "png" ---------------------------- Example 4 ---------------------------- Output user object with __toString Method Result: string(4) "TEST" ---------------------------- Actual result: -------------- ################################################### Testing filter_var with SimpleXMLElement Objects ################################################### Example 1 ---------------------------- DUMP XML Attribute Output: png ---------------------------- Example 2 ---------------------------- Output filter_var Result: bool(false) PROBLEM: in former versions as 5.2.1 result has been 'png' ---------------------------- Example 3 ---------------------------- Output filter_var with active type switching Result: string(3) "png" ---------------------------- Example 4 ---------------------------- Output user object with __toString Method Result: string(4) "TEST" ---------------------------- -- Edit bug report at http://bugs.php.net/bug.php?id=51245&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51245&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51245&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51245&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51245&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51245&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51245&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51245&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51245&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51245&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51245&r=support Expected behavior: http://bugs.php.net/fix.php?id=51245&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51245&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51245&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51245&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51245&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51245&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51245&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51245&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51245&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51245&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51245&r=mysqlcfg