Skip to content

PossiblyUndefinedVariable

A variable is only assigned in some branches and may be unset on other paths.

<?php
function label(bool $flag): string {
if ($flag) {
$text = 'yes';
}
return $text; // $text is not assigned when $flag is false
}

Assign a default before the branch, or handle every branch.

<?php
function label(bool $flag): string {
$text = 'no';
if ($flag) {
$text = 'yes';
}
return $text;
}