Documentation

Variables

Utility functions for use when examining variables.

Table of Contents

$phpReservedVars List of PHP Reserved variables. array
getMemberProperties() Retrieve the visibility and implementation properties of a class member var. array
isPHPReservedVarName() Verify if a given variable name is the name of a PHP reserved variable. bool
isSuperglobal() Verify if a given variable or array key token points to a PHP superglobal. bool
isSuperglobalName() Verify if a given variable name is the name of a PHP superglobal. bool

Properties

$phpReservedVars

List of PHP Reserved variables.

public static array $phpReservedVars = [ '_SERVER' => true, '_GET' => true, '_POST' => true, '_REQUEST' => true, '_SESSION' => true, '_ENV' => true, '_COOKIE' => true, '_FILES' => true, 'GLOBALS' => true, 'http_response_header' => false, 'argc' => false, 'argv' => false, // Deprecated. 'php_errormsg' => false, // Removed PHP 5.4.0. 'HTTP_SERVER_VARS' => false, 'HTTP_GET_VARS' => false, 'HTTP_POST_VARS' => false, 'HTTP_SESSION_VARS' => false, 'HTTP_ENV_VARS' => false, 'HTTP_COOKIE_VARS' => false, 'HTTP_POST_FILES' => false, // Removed PHP 5.6.0. 'HTTP_RAW_POST_DATA' => false, ]
The array keys are the variable names without the leading dollar sign, the values indicate whether the variable is a superglobal or not. {@internal The variables names are set without the leading dollar sign to allow this array to be used with array index keys as well. Think: `'_GET'` in `$GLOBALS['_GET']`.}

Methods

getMemberProperties()

Retrieve the visibility and implementation properties of a class member var.

public static getMemberProperties( $phpcsFile : File , $stackPtr : int ) : array

The format of the return value is:

array( 'scope' => string, // Public, private, or protected. 'scope_specified' => boolean, // TRUE if the scope was explicitly specified. 'is_static' => boolean, // TRUE if the static keyword was found. 'type' => string, // The type of the var (empty if no type specified). 'type_token' => integer, // The stack pointer to the start of the type // or FALSE if there is no type. 'type_end_token' => integer, // The stack pointer to the end of the type // or FALSE if there is no type. 'nullable_type' => boolean, // TRUE if the type is nullable. );

Main differences with the PHPCS version:

  • Removed the parse error warning for properties in interfaces. This will now throw the same "$stackPtr is not a class member var" runtime exception as other non-property variables passed to the method.
  • Defensive coding against incorrect calls to this method.
Parameters
$phpcsFile : File

The file being scanned.

$stackPtr : int

The position in the stack of the T_VARIABLE token to acquire the properties for.

Tags
see

Original source.

see

Cross-version compatible version of the original.

since
throws

If the specified position is not a T_VARIABLE token, or if the position is not a class member variable.

Return values
array

isPHPReservedVarName()

Verify if a given variable name is the name of a PHP reserved variable.

public static isPHPReservedVarName( $name : string ) : bool
Parameters
$name : string

The full variable name with or without leading dollar sign. This allows for passing an array key variable name, such as '_GET' retrieved from $GLOBALS['_GET']. Note: when passing an array key, string quotes are expected to have been stripped already.

Tags
since
Return values
bool

isSuperglobal()

Verify if a given variable or array key token points to a PHP superglobal.

public static isSuperglobal( $phpcsFile : File , $stackPtr : int ) : bool
Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

The position in the stack of a T_VARIABLE token or of the T_CONSTANT_ENCAPSED_STRING array key to a variable in $GLOBALS.

Tags
since
Return values
bool

True if this points to a superglobal. False when not; or when an unsupported token has been passed; or when a T_CONSTANT_ENCAPSED_STRING is not an array index key; or when it is, but not an index to the $GLOBALS variable.

isSuperglobalName()

Verify if a given variable name is the name of a PHP superglobal.

public static isSuperglobalName( $name : string ) : bool
Parameters
$name : string

The full variable name with or without leading dollar sign. This allows for passing an array key variable name, such as '_GET' retrieved from $GLOBALS['_GET']. Note: when passing an array key, string quotes are expected to have been stripped already.

Tags
since
Return values
bool

Search results