website/errors/unset.variable.md
<?php declare(strict_types = 1);
function doFoo(): void
{
unset($undefined);
}
The unset() call targets a variable that does not exist in the current scope. Unsetting an undefined variable is a no-op but usually indicates a bug -- the variable name is likely misspelled, or the logic that was supposed to define the variable is missing or unreachable.
Make sure the variable name is correct and the variable is defined before attempting to unset it:
<?php declare(strict_types = 1);
function doFoo(): void
{
- unset($undefined);
+ $data = getData();
+ // ... use $data ...
+ unset($data);
}
If the unset() call is no longer needed, remove it:
<?php declare(strict_types = 1);
function doFoo(): void
{
- unset($undefined);
}