DEV Community

Programming Dive
Programming Dive

Posted on

1

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;
}

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay