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.
It appears that the string
N;is theserialize()d form ofnull. (See this codepad)However, two things to note:
null. Otherwise you’ll get a notice about$foobeing 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.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 ofserialize()means thanks tounserialize().