© Mikael Olsson 2021
M. OlssonPHP 8 Quick Scripting Referencehttps://doi.org/10.1007/978-1-4842-6619-9_20

20. Variable Testing

Mikael Olsson1  
Hammarland, Finland

As a web-focused language, it is common in PHP to process user-supplied data. Such data needs to be tested before it is used to confirm that it exists and has a valid value. PHP provides a number of built-in constructs that can be used for this purpose.


The isset language construct returns true if the variable exists and has been assigned a value other than null.
isset($a); // false
$a = 10;
isset($a); // true
$a = null;
isset($a); // false


The empty construct checks whether the specified variable has an empty value—such as null, 0, false, or an empty string—and returns true if ...

Get PHP 8 Quick Scripting Reference: A Pocket Guide to PHP Web Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.