-
-
Notifications
You must be signed in to change notification settings - Fork 0
Notes
Just some notes I'm jotting down while I'm figuring out the database object relation mapper.
An object relation mapper in PHP has never been truly possible without workarounds, until PHP 8.4's introduction of lazily loaded objects.
Lazy Objects (https://www.php.net/manual/en/language.oop5.lazy-objects.php) allow a class to store a typed property in a way that its value is not initialised until it is first accessed. This removes any of the recursive issues involved in truly separating OOP code from SQL.
With true deferred object loading, all complexities surrounding joined tables are removed. An object that has a typed property of another object's type will no longer have to build joins into the SQL used to access the data - instead, another select can be emitted only when the property is accessed (might be never). Lazy initialisation of all relations converts all joined table structures into simple one-dimensional select statements that will only execute when the data is accessed.