Oihana PHP System

Char uses ConstantsTrait

Class Char

A comprehensive enumeration of commonly used single-character strings, including punctuation marks, mathematical symbols, whitespace characters, typographic signs, and Unicode superscript/subscript digits.

This class is particularly useful when working with string manipulation, formatting, code generation, or when symbolic constants are preferred over raw string literals for better readability and maintainability.

Features:

  • All constants are strings, representing a wide range of characters.
  • Includes ASCII, Unicode typographic, superscript, and subscript symbols.
  • Helps reduce the use of "magic characters" in your codebase.
  • Designed to be compatible with the ConstantsTrait for reflection or listing.

Example:

use oihana\enums\Char;

echo 'A' . Char::DOT . 'B';               // Outputs: A.B
echo Char::SUPERSCRIPT_TWO;              // Outputs: ²
echo implode(Char::COMMA . Char::SPACE, ['one', 'two', 'three']);
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

AMPERSAND  = "&"
APOSTROPHE  = "'"
ASTERISK  = '*'
AT_SIGN  = '@'
BACK_SLASH  = '\\'
BULLET  = '•'
CHECK_MARK  = '✔'
CIRCUMFLEX  = '^'
COLON  = ':'
COMMA  = ','
COPYRIGHT  = '©'
CROSS_MARK  = '✘'
DASH  = '-'
DEGREE  = '°'
DOLLAR  = '$'
DOT  = '.'
DOUBLE_COLON  = '::'
DOUBLE_DOT  = '..'
DOUBLE_EQUAL  = '=='
DOUBLE_HYPHEN  = '--'
DOUBLE_PIPE  = '||'
DOUBLE_QUOTE  = '"'
DOUBLE_SLASH  = '//'
EM_DASH  = '—'
EMPTY  = ''
EN_DASH  = '–'
EOL  = PHP_EOL
EQUAL  = '='
EURO_SIGN  = '€'
EXCLAMATION_MARK  = '!'
GRAVE_ACCENT  = '`'
HASH  = '#'
HEART  = '♥'
HYPHEN  = '-'
INFINITY  = '∞'
LEFT_BRACE  = '{'
LEFT_BRACKET  = '['
LEFT_PARENTHESIS  = '('
MICRO_SIGN  = 'µ'
MODULUS  = '%'
NUMBER  = '#'
PERCENT  = '%'
PILCROW  = '¶'
PIPE  = '|'
PLUS  = '+'
PLUS_MINUS  = '±'
QUESTION_MARK  = '?'
QUOTATION_MARK  = '"'
REGISTERED  = '®'
RIGHT_BRACE  = '}'
RIGHT_BRACKET  = ']'
RIGHT_PARENTHESIS  = ')'
SECTION_SIGN  = '§'
SEMI_COLON  = ';'
SIMPLE_QUOTE  = "'"
SLASH  = '/'
SNOWFLAKE  = '❄'
SPACE  = ' '
SUBSCRIPT_EIGHT  = '₈'
SUBSCRIPT_EQUAL  = '₌'
SUBSCRIPT_FIVE  = '₅'
SUBSCRIPT_FOUR  = '₄'
SUBSCRIPT_LEFT_PARENTHESIS  = '₍'
SUBSCRIPT_MINUS  = '₋'
SUBSCRIPT_NINE  = '₉'
SUBSCRIPT_ONE  = '₁'
SUBSCRIPT_PLUS  = '₊'
SUBSCRIPT_RIGHT_PARENTHESIS  = '₎'
SUBSCRIPT_SEVEN  = '₇'
SUBSCRIPT_SIX  = '₆'
SUBSCRIPT_THREE  = '₃'
SUBSCRIPT_TWO  = '₂'
SUBSCRIPT_ZERO  = '₀'
SUPERSCRIPT_EIGHT  = '⁸'
SUPERSCRIPT_EQUAL  = '⁼'
SUPERSCRIPT_FIVE  = '⁵'
SUPERSCRIPT_FOUR  = '⁴'
SUPERSCRIPT_LEFT_PARENTHESIS  = '⁽'
SUPERSCRIPT_MINUS  = '⁻'
SUPERSCRIPT_NINE  = '⁹'
SUPERSCRIPT_ONE  = '¹'
SUPERSCRIPT_PLUS  = '⁺'
SUPERSCRIPT_RIGHT_PARENTHESIS  = '⁾'
SUPERSCRIPT_SEVEN  = '⁷'
SUPERSCRIPT_SIX  = '⁶'
SUPERSCRIPT_THREE  = '³'
SUPERSCRIPT_TWO  = '²'
SUPERSCRIPT_ZERO  = '⁰'
TILDE  = '~'
TRADEMARK  = '™'
TRIPLE_DOT  = '...'
UNDERLINE  = '_'

Properties

$ALL  : array<string|int, mixed>|null
The list of all constants.
$CONSTANTS  : array<string|int, mixed>|null
The flipped list of all constants.

Methods

enums()  : array<string|int, mixed>
Returns an array of all constants in this enumeration.
get()  : mixed
Returns a valid enumeration value or the default value.
getAll()  : array<string, string>
Returns an array of constants in this class.
getConstant()  : string|array<string|int, string>|null
Returns the constant name(s) associated with the given value.
includes()  : bool
Checks if a given value is valid (exists as a constant in this class).
resetCaches()  : void
Reset the internal cache of the static methods.
validate()  : void
Validates if the passed-in value is a valid element in the current enum.

Constants

AMPERSAND

public mixed AMPERSAND = "&"

APOSTROPHE

public mixed APOSTROPHE = "'"

ASTERISK

public mixed ASTERISK = '*'

AT_SIGN

public mixed AT_SIGN = '@'

BACK_SLASH

public mixed BACK_SLASH = '\\'

BULLET

public mixed BULLET = '•'

CHECK_MARK

public mixed CHECK_MARK = '✔'

CIRCUMFLEX

public mixed CIRCUMFLEX = '^'

COLON

public mixed COLON = ':'

COMMA

public mixed COMMA = ','
public mixed COPYRIGHT = '©'

CROSS_MARK

public mixed CROSS_MARK = '✘'

DASH

public mixed DASH = '-'

DEGREE

public mixed DEGREE = '°'

DOLLAR

public mixed DOLLAR = '$'

DOT

public mixed DOT = '.'

DOUBLE_COLON

public mixed DOUBLE_COLON = '::'

DOUBLE_DOT

public mixed DOUBLE_DOT = '..'

DOUBLE_EQUAL

public mixed DOUBLE_EQUAL = '=='

DOUBLE_HYPHEN

public mixed DOUBLE_HYPHEN = '--'

DOUBLE_PIPE

public mixed DOUBLE_PIPE = '||'

DOUBLE_QUOTE

public mixed DOUBLE_QUOTE = '"'

DOUBLE_SLASH

public mixed DOUBLE_SLASH = '//'

EM_DASH

public mixed EM_DASH = '—'

EMPTY

public mixed EMPTY = ''

EN_DASH

public mixed EN_DASH = '–'

EOL

public mixed EOL = PHP_EOL

EQUAL

public mixed EQUAL = '='

EURO_SIGN

public mixed EURO_SIGN = '€'

EXCLAMATION_MARK

public mixed EXCLAMATION_MARK = '!'

GRAVE_ACCENT

public mixed GRAVE_ACCENT = '`'

HASH

public mixed HASH = '#'

HEART

public mixed HEART = '♥'

HYPHEN

public mixed HYPHEN = '-'

INFINITY

public mixed INFINITY = '∞'

LEFT_BRACE

public mixed LEFT_BRACE = '{'

LEFT_BRACKET

public mixed LEFT_BRACKET = '['

LEFT_PARENTHESIS

public mixed LEFT_PARENTHESIS = '('

MICRO_SIGN

public mixed MICRO_SIGN = 'µ'

MODULUS

public mixed MODULUS = '%'

NUMBER

public mixed NUMBER = '#'

PERCENT

public mixed PERCENT = '%'

PILCROW

public mixed PILCROW = '¶'

PIPE

public mixed PIPE = '|'

PLUS

public mixed PLUS = '+'

PLUS_MINUS

public mixed PLUS_MINUS = '±'

QUESTION_MARK

public mixed QUESTION_MARK = '?'

QUOTATION_MARK

public mixed QUOTATION_MARK = '"'

REGISTERED

public mixed REGISTERED = '®'

RIGHT_BRACE

public mixed RIGHT_BRACE = '}'

RIGHT_BRACKET

public mixed RIGHT_BRACKET = ']'

RIGHT_PARENTHESIS

public mixed RIGHT_PARENTHESIS = ')'

SECTION_SIGN

public mixed SECTION_SIGN = '§'

SEMI_COLON

public mixed SEMI_COLON = ';'

SIMPLE_QUOTE

public mixed SIMPLE_QUOTE = "'"

SLASH

public mixed SLASH = '/'

SNOWFLAKE

public mixed SNOWFLAKE = '❄'

SPACE

public mixed SPACE = ' '

SUBSCRIPT_EIGHT

public mixed SUBSCRIPT_EIGHT = '₈'

SUBSCRIPT_EQUAL

public mixed SUBSCRIPT_EQUAL = '₌'

SUBSCRIPT_FIVE

public mixed SUBSCRIPT_FIVE = '₅'

SUBSCRIPT_FOUR

public mixed SUBSCRIPT_FOUR = '₄'

SUBSCRIPT_LEFT_PARENTHESIS

public mixed SUBSCRIPT_LEFT_PARENTHESIS = '₍'

SUBSCRIPT_MINUS

public mixed SUBSCRIPT_MINUS = '₋'

SUBSCRIPT_NINE

public mixed SUBSCRIPT_NINE = '₉'

SUBSCRIPT_ONE

public mixed SUBSCRIPT_ONE = '₁'

SUBSCRIPT_PLUS

public mixed SUBSCRIPT_PLUS = '₊'

SUBSCRIPT_RIGHT_PARENTHESIS

public mixed SUBSCRIPT_RIGHT_PARENTHESIS = '₎'

SUBSCRIPT_SEVEN

public mixed SUBSCRIPT_SEVEN = '₇'

SUBSCRIPT_SIX

public mixed SUBSCRIPT_SIX = '₆'

SUBSCRIPT_THREE

public mixed SUBSCRIPT_THREE = '₃'

SUBSCRIPT_TWO

public mixed SUBSCRIPT_TWO = '₂'

SUBSCRIPT_ZERO

public mixed SUBSCRIPT_ZERO = '₀'

SUPERSCRIPT_EIGHT

public mixed SUPERSCRIPT_EIGHT = '⁸'

SUPERSCRIPT_EQUAL

public mixed SUPERSCRIPT_EQUAL = '⁼'

SUPERSCRIPT_FIVE

public mixed SUPERSCRIPT_FIVE = '⁵'

SUPERSCRIPT_FOUR

public mixed SUPERSCRIPT_FOUR = '⁴'

SUPERSCRIPT_LEFT_PARENTHESIS

public mixed SUPERSCRIPT_LEFT_PARENTHESIS = '⁽'

SUPERSCRIPT_MINUS

public mixed SUPERSCRIPT_MINUS = '⁻'

SUPERSCRIPT_NINE

public mixed SUPERSCRIPT_NINE = '⁹'

SUPERSCRIPT_ONE

public mixed SUPERSCRIPT_ONE = '¹'

SUPERSCRIPT_PLUS

public mixed SUPERSCRIPT_PLUS = '⁺'

SUPERSCRIPT_RIGHT_PARENTHESIS

public mixed SUPERSCRIPT_RIGHT_PARENTHESIS = '⁾'

SUPERSCRIPT_SEVEN

public mixed SUPERSCRIPT_SEVEN = '⁷'

SUPERSCRIPT_SIX

public mixed SUPERSCRIPT_SIX = '⁶'

SUPERSCRIPT_THREE

public mixed SUPERSCRIPT_THREE = '³'

SUPERSCRIPT_TWO

public mixed SUPERSCRIPT_TWO = '²'

SUPERSCRIPT_ZERO

public mixed SUPERSCRIPT_ZERO = '⁰'

TILDE

public mixed TILDE = '~'

TRADEMARK

public mixed TRADEMARK = '™'

TRIPLE_DOT

public mixed TRIPLE_DOT = '...'

UNDERLINE

public mixed UNDERLINE = '_'

Properties

$ALL

The list of all constants.

protected static array<string|int, mixed>|null $ALL = null

$CONSTANTS

The flipped list of all constants.

protected static array<string|int, mixed>|null $CONSTANTS = null

Methods

enums()

Returns an array of all constants in this enumeration.

public static enums([int $flags = SORT_STRING ]) : array<string|int, mixed>
Parameters
$flags : int = SORT_STRING

The optional second parameter flags may be used to modify the comparison behavior using these values: Comparison type flags:

  • SORT_REGULAR - compare items normally (don't change types)
  • SORT_NUMERIC - compare items numerically
  • SORT_STRING - compare items as strings
  • SORT_LOCALE_STRING - compare items as strings, based on the current locale.
Return values
array<string|int, mixed>

get()

Returns a valid enumeration value or the default value.

public static get(mixed $value[, mixed|null $default = null ]) : mixed
Parameters
$value : mixed
$default : mixed|null = null

getAll()

Returns an array of constants in this class.

public static getAll() : array<string, string>
Return values
array<string, string>

getConstant()

Returns the constant name(s) associated with the given value.

public static getConstant(string $value[, string|array<string|int, string>|null $separator = null ]) : string|array<string|int, string>|null

This method searches the class constants for one or multiple constants whose value matches (or contains) the provided value.

If the constant values are strings containing multiple parts separated by one or more separators, it splits them accordingly before matching.

The method returns:

  • a string with the constant name if exactly one constant matches,
  • an array of constant names if multiple constants share the same value,
  • or null if no constant matches the given value.

The internal cache is used to optimize repeated lookups.

Parameters
$value : string

The value to search for among the constants.

$separator : string|array<string|int, string>|null = null

Optional separator(s) to split constant values before matching.

  • If null, no splitting is performed.
  • If a string, it is used as the delimiter.
  • If an array of strings, each separator is applied iteratively.
Return values
string|array<string|int, string>|null

The constant name(s) matching the value, or null if none found.

includes()

Checks if a given value is valid (exists as a constant in this class).

public static includes(mixed $value[, bool $strict = false ][, string|null $separator = null ]) : bool
Parameters
$value : mixed
$strict : bool = false

[optional]

If the third parameter strict is set to true then the in_array function will also check the types of the needle in the haystack.

$separator : string|null = null

The optional string separator if the constant value contains multiple values in a single string expression.

Return values
bool

True if the value exist, False otherwise.

resetCaches()

Reset the internal cache of the static methods.

public static resetCaches() : void

validate()

Validates if the passed-in value is a valid element in the current enum.

public static validate(mixed $value[, bool $strict = true ][, string|null $separator = null ]) : void
Parameters
$value : mixed
$strict : bool = true

[optional]

If the third parameter strict is set to true then the in_array function will also check the types of the needle in the haystack.

$separator : string|null = null

The optional string separator if the constant value contains multiple values in a single string expression.

Tags
throws
ConstantException

Thrown when the passed-in value is not a valid constant.


        
On this page

Search results