Join my Laravel for REST API's course on Udemy 👀

PHP: Check if a variable exists

June 20, 2022  ‐ 1 min read

Referencing a variable that hasn't been set in PHP fails rather silently. You might see a PHP warning like the following:

PHP Warning:  Undefined variable $var

To check whether a variable has been set in PHP we use the isset() function, which returns false if the passed variable has not been set.


if (isset($var) === false)
  echo 'Variable has not been set';