Bug #70882 [NEW]: Inconsistent return value for FILTER_SANITIZE_... when applied to empty objects

From: Date: Mon, 09 Nov 2015 14:29:48 +0000
Subject: Bug #70882 [NEW]: Inconsistent return value for FILTER_SANITIZE_... when applied to empty objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197130@lists.php.net to get a copy of this message
From: bugs dot php dot net_nospam at adviesenzo dot nl Operating system: PHP version: 7.0.0RC6 Package: Filter related Bug Type: Bug Bug description:Inconsistent return value for FILTER_SANITIZE_... when applied to empty objects Description: ------------ Using filter_var() with any of the FILTER_SANITIZE_... filters will return either the sanitized value or an empty string. This works for every single type of variable *but* an empty object. With an empty object it returns false or in the case the FILTER_NULL_ON_FAILURE flag is set false in PHP 5 or null in PHP 7 (related: https://bugs.php.net/bug.php?id=67167 ). Behaviour can be observed in numerous PHP versions here: http://phpcheatsheets.com/test/filter_extension_bool_int_float/ http://phpcheatsheets.com/test/filter_extension_strings/ Test script: --------------- var_dump( filter_var( null, FILTER_SANITIZE_STRING ) ); // prints '' var_dump( filter_var( '', FILTER_SANITIZE_STRING ) ); // prints '' var_dump( filter_var( new stdClass(), FILTER_SANITIZE_STRING ) ); // prints bool(false) var_dump( filter_var( null, FILTER_SANITIZE_NUMBER_FLOAT ) ); // prints '' var_dump( filter_var( '', FILTER_SANITIZE_NUMBER_FLOAT ) ); // prints '' var_dump( filter_var( new stdClass(), FILTER_SANITIZE_NUMBER_FLOAT ) ); // prints bool(false) var_dump( filter_var( null, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ) ); // prints '' var_dump( filter_var( '', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ) ); // prints '' var_dump( filter_var( new stdClass(), FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ) ); // prints NULL Expected result: ---------------- When a sanitize filter is used on an empty object, I would expect PHP to return an empty string. This would make the behaviour more consistent. -- Edit bug report at https://bugs.php.net/bug.php?id=70882&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70882&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70882&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70882&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70882&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70882&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70882&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70882&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70882&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70882&r=support Expected behavior: https://bugs.php.net/fix.php?id=70882&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70882&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70882&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70882&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70882&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70882&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70882&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70882&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70882&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70882&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70882&r=mysqlcfg

« previous php.bugs (#197130) next »