PHPCSUtils

NamingConventions

Utility functions for working with identifier names.

Identifier names in PHP are:

Tags
since
1.0.0-alpha3

Table of Contents

AZ_LOWER  = 'abcdefghijklmnopqrstuvwxyz'
Lowercase a-z.
AZ_UPPER  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Uppercase A-Z.
PHP_LABEL_REGEX  = '`^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$`'
Regular expression to check if a given identifier name is valid for use in PHP.
isEqual()  : bool
Check if two arbitrary identifier names will be seen as the same in PHP.
isValidIdentifierName()  : bool
Verify whether an arbitrary text string is valid as an identifier name in PHP.

Constants

AZ_LOWER

Lowercase a-z.

public string AZ_LOWER = 'abcdefghijklmnopqrstuvwxyz'
Tags
since
1.0.0

AZ_UPPER

Uppercase A-Z.

public string AZ_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Tags
since
1.0.0

PHP_LABEL_REGEX

Regular expression to check if a given identifier name is valid for use in PHP.

public string PHP_LABEL_REGEX = '`^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$`'
Tags
since
1.0.0

Methods

isEqual()

Check if two arbitrary identifier names will be seen as the same in PHP.

public static isEqual(string $nameA, string $nameB) : bool

This method should not be used for variable or constant names, but should be used when comparing namespace, class/trait/interface and function names.

Variable and constant names in PHP are case-sensitive, except for constants explicitely declared case-insensitive using the third parameter for define().

All other names are case-insensitive for the most part, but as it's PHP, not completely. Basically ASCII chars used are case-insensitive, but anything from 0x80 up is case-sensitive.

This method takes this case-(in)sensitivity into account when comparing identifier names.

Note: this method does not check whether the passed names would be valid for identifiers! The \PHPCSUtils\Utils\NamingConventions::isValidIdentifierName() method should be used to verify that, if necessary.

Parameters
$nameA : string

The first identifier name.

$nameB : string

The second identifier name.

Tags
since
1.0.0
Return values
bool

TRUE if these names would be considered the same in PHP; FALSE otherwise.

isValidIdentifierName()

Verify whether an arbitrary text string is valid as an identifier name in PHP.

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

The name to verify.

Note: for variable names, the leading dollar sign - $ - needs to be removed prior to passing the name to this method.

Tags
since
1.0.0
Return values
bool

Search results