1.2.594. Invalid Cast

Some cast operations not permitted.

  • (string) on an object whose class doesn’t have a __toString method

  • (int) on any object, except certain PHP native ones

  • (string) on an array: this will produce the Array string, which is useless.

<?php

class Foo {}

(string) new Foo();     // Error

print (string) array(); // Array

?>

1.2.594.1. Specs

Short name

Structures/InvalidCast

Rulesets

All, Analyze, Changed Behavior, LintButWontExec

Exakat since

2.6.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

cast

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud