[wp-trac] [WordPress Trac] #18026: stripslashes_deep() casts booleans to strings

WordPress Trac wp-trac at lists.automattic.com
Thu Jul 7 16:54:00 UTC 2011


#18026: stripslashes_deep() casts booleans to strings
--------------------------+------------------------------
 Reporter:  DemoIgor      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by knutsp):

 I see. That makes sense.

 I found this comment on http://php.net/manual/en/function.stripslashes.php

 ----

 2) both stripslashes and str_replace functions always return strings, so:

 * TRUE will become a string "1",
 * FALSE will become an empty string,
 * integers and floats will become strings,
 * NULL will become an empty string.

 On the other hand you only need to process strings, so use the is_string
 function to check;
 ----
 If so, then the function could be exptended a bit like this:
 {{{
 function stripslashes_deep($value) {
     $value = is_array($value) ?
         array_map('stripslashes_deep', $value) :
         (is_string($value)?
             stripslashes($value):
             $value);

     return $value;
  }
 }}}
 But I don't like the  $value = $value so I would prefer using if blocks
 instead of nested ternal if's.

 Test:
 {{{
 var_dump( stripslashes_deep( array( 'foo' => true, 'bar' => false,
 'string' => 'str\ing', 'array' => array( 'foo1' => true, 'bar1' => false,
 'arr1' => 'arr\1', 'arr2' => 'arr\2') ) ) );
 }}}
 Result:
 array(4) { ["foo"]=> bool(true) ["bar"]=> bool(false) ["string"]=>
 string(6) "string" ["array"]=> array(4) { ["foo1"]=> bool(true) ["bar1"]=>
 bool(false) ["arr1"]=> string(4) "arr1" ["arr2"]=> string(4) "arr2" } }

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18026#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list