TypedData
To really understand how entity data is modeled, we need to understand the TypedData API. Unfortunately, this API 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 this API was needed in the first place. 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.
Since PHP 7, we have type-hinting for scalar values in function parameters, which is good, but still not enough. Scalar values alone are not going to cut it if you think of the difference between 1495875076
and 2495877076
. The first is a timestamp while the second is an integer...