TypedData
In order to really understand how entity data is modeled, we need to understand the TypedData API. Unfortunately, this API still remains quite a mystery for many. But you're in luck because, in this section, we're going to get to the bottom of it.
Why TypedData?
It helps to understand things better if we first talk about why there was the need for this API. It all has to do with the way PHP as a language is, compared to others, and that is, loosely typed. This means that in PHP it is very difficult to use native language constructs to rely on the type of certain data or understand more about that data.
The difference between the string "1"
and integer 1
is a very common example. We are often afraid of using the ===
sign to compare them because we never know what they actually come back as from the database or wherever. So, we either use ==
(which is not really good) or forcefully cast them to the same type and hope PHP will be able to get it right...