1.2.1119. Should Use Operator

Some functions duplicate the feature of an operator. When in doubt, it is better to use the operator.

Beware, some edge cases may apply. In particular, backward compatibility may prevent usage of newer features.

  • array_push() is equivalent to []

  • is_object() is equivalent to instanceof

  • function_get_arg() and function_get_args() is equivalent to ellipsis :

  • chr() is equivalent to string escape sequences, such as \n, \x69, u{04699}

  • call_user_func() is equivalent to $functionName(arguments), $object->$method(`... <https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list>`_$arguments)

  • is_null() is equivalent to === null

  • php_version() is equivalent to PHP_VERSION (the constant)

  • is_array(), is_int(), is_object(), etc. is equivalent to a scalar type

1.2.1119.1. Suggestions

  • Use [] instead of array_push()

  • Use instanceof instead of is_object()

  • Use … instead of function_get_arg() and function_get_args()

  • Use escape sequences instead of chr()

  • Use dynamic function call instead of call_user_func()

  • Use === null instead of is_null()

  • Use PHP_VERSION instead of php_version()

  • Use type instead of is_int(), is_string(), is_bool(), etc.

1.2.1119.2. Specs

Short name

Structures/ShouldUseOperator

Rulesets

All, Changed Behavior, Suggestions

Exakat since

1.3.0

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Examples

Zencart, SugarCrm

Available in

Entreprise Edition, Exakat Cloud