1.2.1351. Use get_debug_type()

get_debug_type() returns the given type of a variable. It was introduced in PHP 8.0: this makes it incompatible with previous versions.

<?php
  // From the RFC
  throw new TypeError('Expected ' . Foo::class . ' got ' . (is_object($bar) ? get_class($bar) : gettype($bar)));

  // Becomes
  throw new TypeError('Expected ' . Foo::class . ' got ' . get_debug_type($bar));

?>

See also PHP RFC: get_debug_type.

1.2.1351.1. Suggestions

  • Replace the ternary with a call to get_debug_type()

1.2.1351.2. Specs

Short name

Php/UseGetDebugType

Rulesets

All, Suggestions

Exakat since

2.1.9

PHP Version

With PHP 8.0 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud