The Difference Between Null, Empty And Zero-Length Data / Strings
A common problem faced by new programmers is understanding the difference between null, empty and zero-length variables, especially when working with database records.
While, for most intents and purposes, the three things have the same effect — either you have some data you can work with, or you don’t — they arise from different circumstances. Understanding how null, empty and zero-length are different can help you avoid data errors in your programs.
The short version is this: If a variable simply doesn’t exist — usually because it hasn’t been declared, but sometimes because it hasn’t been assigned a value — it’s null. If the variable exists but contains no data, it’s empty. And if a structured data variable, such as an array, exists but doesn’t contain any items, it’s zero-length.
An analogy is in order.
Think of a database as a house. A house has rooms, and in each of these rooms are furniture and accessories that are appropriate to that room.
For example, the kitchen has a stove, refrigerator and sink. The bedroom has a dresser, bed and armoire. The living room has a couch, television and coffee table.
Continue reading ‘The Difference Between Null, Empty And Zero-Length Data / Strings’ »