While on vacation I started some prep work for using MongoDB at DailyLit, which is mostly written in PHP. The prep work consists of creating a lightweight way of getting PHP objects in and out of MongoDB (I know there are some things out there already, but what’s the fun in that?).
Here is a slightly simplified summary what I am shooting for:
I like the idea of using static/class methods for retrieval because these will be generating one or more objects and I do not want to have to deal with separate factory or builder classes. Unfortunately, I encountered some annoying PHP static:
This prints “Fruit” – what the flagnard? For my plan to work, I need this to print “Apple”.
First, lets establish that “Apple” is not an unreasonable expectation. In Python, I can do the following:
This prints “Apple” (well, actually it prints “__main__.Apple”).
In Ruby, I can do this:
![highlight](https://storage.googleapis.com/papyrus_images/dbfe4bc5ef4dcd8fbcbebcc517c79fa5.webp)
![Continuations logo](/_next/image?url=https%3A%2F%2Fstorage.googleapis.com%2Fpapyrus_images%2Fe3f4eb1044178c979fd42b642565dbab.jpg&w=384&q=75)