Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Attempt to assign property “%s” on null

Description

null is not an object, and it can’t be used as such. Until PHP 8.0, the engine would automatically create a stdClass object, and replace the null value with it. This is not the case anymore.

Example

<?php

$a = null;

$a->b = 1;

?>

Literal Examples

  • Attempt to assign property “b” on null

Alternatives

  • Instantiate any object and replace null with it.
  • Explicitly instantiate a stdClass object and replace null with it.
  • Remove the property usage.
  • Use another variable to use this property.

In previous PHP versions, this error message used to be :ref:creating-default-object-from-empty-value.