php serialize undefined variable
php, serialization
Solution
It appears that the string `N;` is the `serialize()`d form of `null`. (See this codepad) However, two things to note:
- You should be defining all variables before using them, even if you just declare them as `null`. Otherwise you'll get a notice about `$foo` being an undefined variable. Some argue that you can hide warnings, but this is poor practice. You should prevent them completely by using sensible defaults for all variables.
- Typically, one does not need to read the output of `serialize()`. You can store it on a DB, in a file, or in a memory cache system like Memcached, APC, or Redis. However, you will never need to understand what the output of `serialize()` means thanks to `unserialize()`.
Problem
I have the following; ``` $foo; $foo = serialize($foo); print_r($foo); it gave me a result of N; ``` Now I do not know if this is unique to the system i am using or if this is a normal result. All I know is it was causing major problems with my site. My question is... is this normal when serializing an undefined variable?If so can someone please explain why it outputs this result.Thank you for your time.