[wp-trac] [WordPress Trac] #53946: Improve return types for sanitizing/escaping functions

WordPress Trac noreply at wordpress.org
Tue Aug 17 20:41:56 UTC 2021


#53946: Improve return types for sanitizing/escaping functions
--------------------------+-----------------------------
 Reporter:  malthert      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The return type of functions where param is string|array, specificall
 escaping and sanitizing functions, should be set more specific (= that the
 function returns the same type the passed $arg has).

 This means changing:

 {{{#!php
 <?php
      * @param string|array $value String or array of data to unslash.
      * @return string|array Unslashed $value.
      */
     function wp_unslash($value)

 to this:

      * @param string|array $value String or array of data to unslash.
      * @return ($value is array ? array : string) Unslashed $value.
      */
     function wp_unslash($value)
 }}}

 This ensures that static analysis tools correctly infer the type, as well
 as make it clear to developers that the variable type is not changed by
 this function.

 This is filed as bug, since it is a (more and more) deprecated way of
 declaring phpdocs, thus should be updated.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53946>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list