Skip to content

Commit 2d55461

Browse files
authored
Added null references doc
1 parent c280ce2 commit 2d55461

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

doc/null-references

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[<-- Return to index](../README.md)
2+
# Null/Nil References
3+
4+
### What does the language call these?
5+
#### PHP
6+
PHP calls variables with no value [`NULL`s](https://secure.php.net/manual/en/language.types.null.php). Variables are NULL if they are manually assigned as such, their value has never been set to anything before, or they are unset via the [`unset()`](https://secure.php.net/manual/en/function.unset.php) method.
7+
#### Python
8+
Python calls variables with no value `None`.
9+
10+
### What are the features of handling these?
11+
#### PHP
12+
Variables can be unset via the [`unset()`](https://secure.php.net/manual/en/function.unset.php) method and will become NULL.
13+
14+
Variables can be checked against null via the [`is_null()`](https://secure.php.net/manual/en/function.is-null.php) method.
15+
#### Python
16+
In Python, `None` is actually an object, and behaves like one. Under the hood, `None` is of type `NoneType`. Variables can be checked against None programmatically just like any other object comparison:
17+
```python
18+
class myClass:
19+
def __init__(self, foo, bar):
20+
self.foo = foo
21+
self.bar = bar
22+
23+
a = myClass("apples", "oranges")
24+
b = None
25+
26+
print("a is not None") if (a is not None) else print("a is None")
27+
print("b is not None") if (b is not None) else print("b is None")
28+
```
29+
Will yield:
30+
```
31+
a is not None
32+
b is None
33+
```

0 commit comments

Comments
 (0)