Clearing Up Some Annoying PHP Static

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:

Loading...
highlight
Collect this post to permanently own it.
Continuations logo
Subscribe to Continuations and never miss a post.