DEV Community

Programming Dive
Programming Dive

Posted on

is_null vs null in php

As per the php.net site documentation, is_null() function finds whether provided variable is NULL.

Actually, is_null() function works similar like isset() but as its opposite. So it returns TRUE in all the cases except when there is no value assigned to a variable OR assigned as NULL.

https://programmingdive.com/is-null-vs-null-in-php/

Top comments (1)

Collapse
 
patricnox profile image
PatricNox

A useful addition is empty() which basically can be treated as isset (since it covers it) but for moments where you explictly don't seek to know whether the actual value is set.

empty() also works on object members, whilst isset() does not.

if (empty($object->member)) {
   return true;
}