The (unset) cast is deprecated

Description

Removing a variable, a property or an array index with the cast operator (unset) is deprecated since PHP 7.4, and will be removed in PHP 8.0. It is recommnded to do it with the unset() function.

Example

<?php

(unset) $x;

?>

Solutions

  • Use the unset() function to remove variables.

  • Assign null to the variable.

In more recent PHP versions, this error message is now The (unset) cast is no longer supported.