Documentation

ArrayWalkingFunctionsHelper

FinalYes

Helper functions and function lists for checking whether a function applies a callback to an array.

Tags
since
3.0.0

The property in this class was previously contained in the WordPressCS\WordPress\Sniff class and has been moved here.

Table of Contents

Properties

$arrayWalkingFunctions  : array<string, array<string|int, mixed>>
List of array functions which apply a callback to the array.

Methods

get_callback_parameter()  : array<string|int, mixed>|false
Retrieve the parameter information for the callback parameter for an array walking function.
get_functions()  : array<string, bool>
Retrieve a list of the supported "array walking" functions.
is_array_walking_function()  : bool
Check if a particular function is an "array walking" function.

Properties

$arrayWalkingFunctions

List of array functions which apply a callback to the array.

private static array<string, array<string|int, mixed>> $arrayWalkingFunctions = array('array_map' => array('position' => 1, 'name' => 'callback'), 'map_deep' => array('position' => 2, 'name' => 'callback'))

These are often used for sanitization/escaping an array variable.

Note: functions which alter the array by reference are not listed here on purpose. These cannot easily be used for sanitization as they can't be combined with unslashing. Similarly, they cannot be used for late escaping as the return value is a boolean, not the altered array.

Tags
since
2.1.0
since
3.0.0
  • Moved from the Sniff class to this class.
  • Visibility changed from protected to private and property made static. Use the get_functions() method for access.
  • The value has changed from an integer to an array containing the integer parameter position + its name.

Methods

get_callback_parameter()

Retrieve the parameter information for the callback parameter for an array walking function.

public static get_callback_parameter(File $phpcsFile, int $stackPtr) : array<string|int, mixed>|false
Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position of function call name token.

Tags
since
3.0.0
Return values
array<string|int, mixed>|false

Array with information on the callback parameter. Or FALSE if the parameter is not found. See the PHPCSUtils PassedParameters::getParameters() documentation for the format of the returned (single-dimensional) array.

get_functions()

Retrieve a list of the supported "array walking" functions.

public static get_functions() : array<string, bool>
Tags
since
3.0.0
Return values
array<string, bool>

is_array_walking_function()

Check if a particular function is an "array walking" function.

public static is_array_walking_function(string $functionName) : bool
Parameters
$functionName : string

The name of the function to check.

Tags
since
3.0.0
Return values
bool

        
On this page

Search results