|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-03-09 11:36 UTC] a dot dorn at sitesol dot de
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"
----------------------------
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
Here is the small script: $xmlstring = '<?xml version="1.0" encoding="iso-8859-1"?'.'><file ext="png"> <user id="XXX"/> </file>'; $xml = simplexml_load_string($xmlstring); echo var_dump(filter_var($xml["ext"], FILTER_SANITIZE_STRING));