Attempt to read property “%s” on %s

Description

This error reports that a non-object was used with an object syntax. Non-objects are integers, floats, strings, null, booleans, etc.

This is a warning, so PHP will continue execution, using null as a result of this operation.

Example

<?php

$integer = 1;
var_dump($integer->a);

$array = [3];
var_dump($array?->a);

?>

Literal Examples

  • Attempt to read property “a” on int

  • Attempt to read property “a” on array

  • Attempt to read property “a” on float

  • Attempt to read property “a” on string

  • Attempt to read property “a” on bool

Solutions

  • Remove the use of the property.

  • Add a type to the underlying variable, to ensure it is an object.

  • Check the variable is an object.