The (unset) cast is no longer supported

Description

Removing a variable, a property or an array index with the cast operator (unset) was removed in PHP 8.0. It has to be done with the unset() function.

Example

<?php

(unset) $x;

?>

Solutions

  • Use the unset() function to remove variables.

  • Assign null to the variable.

In previous PHP versions, this error message used to be The (unset) cast is deprecated.