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

No Warning For Unused Variables

<?php

  $a;
  // crii crii 
  
  3 || $b; 
  // ...
  
  echo $c;
  // Warning: Undefined variable $c
  
?>

PHP variable optimisation in action: the undefined variables are only reported when they are used.

The first is omitted : there are no operations.

The second is skipped : no need to execute the second term of the or.

The third is reporting a warning.

Of course, an assignation is not reported with an undefined variable, as it will be set. Although, may be reusage of a variable could be reported.

See Also

PHP Features

Last updated: 10 September 2026