What is the exact difference between null, 0, false, and an empty string in PHP? Is null similar to None in python?
Asked
Active
Viewed 153 times
-2
Vishnu Jayan
- 149
- 3
- 16
-
1And no, it is not similar to `None` in Python, which is an actual value. `null` means there is no value at all. – Martijn Pieters Oct 15 '18 at 11:14
-
Like @MartijnPieters said `None` is a Object in Python and will use up some memory.. Well the `NULL` in PHP and other programming languages which uses `NULL` will clear the memory for that variable some languages will use some kind of garbage collector... Python `None` is more similair to PHP's `StdClass` and basically Python syntax to check for None `if – Raymond Nijland Oct 15 '18 at 12:09
-
1@ozgur: why did this need reopening? This is basically a PHP question, the minor 'is this the same as Python's None' angle has already been addressed in a comment and doesn't require a separate answer. If you feel a post needs re-opening, please do let me know and we can discuss this. We could add a separate duplicate target about the nature of the Python `None` object, for example. – Martijn Pieters Oct 15 '18 at 12:13
1 Answers
1
Well, after massive comments and then poof deletion of them... may as well try to help you out.
null is the absence of value.
0 can be a numeric value, or a representation of a boolean FALSE, or a string. PHP doesn't really have variable typing, so depending on what you are checking for using ==0 or ===0 or ==false or ===false may be appropriate.
You may want to read over this - https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ as well as the PHP manual for isset() and empty()
ivanivan
- 2,155
- 2
- 10
- 11