Home

Dynamic Classes in PHP: Part II


After taking a look at what’s available to me in the way of creating polymorphic functions in PHP, I’ve come to the conclusion that my idea has a snowball’s chance in hell of working ;)

I took a look at some functions called create_function which, despite its exciting name, turns out only to be for simple anonymous lambda-type functions. Nothing as complex as I’m wanting. To top it off you can’t make them persistent and you can’t even set a name for them ;)

What I’ve decided might be a better solution (and it still automated) would be to ditch my pile of utility functions like

CalEvent::getEventName(), EventRecursion::setRecursionFrequency($recursion_id, $freq) 

and their associated helper classes in XtremeCalendar like

XtremeCalendar::setEventRecursionFrequency($event_id, $recursion_id, $freq) 

and implement single get and set functions that take an extra parameter in the form of the name of the class variable you want to get/set.

For example, currently to set an event’s name you either have to access the method CalEvent::setEventName($name) directly or use my helper class that tacks on the function XtremeCalendar::setEventName($event_id, $name) would call the functions CalEvent::setVariable($variable, $value) or XtremeCalendar::setEventVariable($event_id, $variable, $value)

This would help me out in a few ways. Number one I would be able to implment my idea of extending the class by simply tacking on a second field definition array for the extended fields and processing that seperately if needed, all the while just calling CalEvent::setVariable.

I’m assuming I would just use Variable variables within that function to set what the user wants.Something along the lines of:

function setVariable($variable, $value) { $this-\>{$variable} = $value; }

If that would work it would eliminate nearly half the number of functions in each of classes and would make my life a lot easier. Obviously I would make sure that the user is allowed to set random variables in the class by checking what they want to set/get against the field array but that’s also pretty trivial.

I’m actually pretty excited because now I have something to do over spring break ;)

Also on spring break I’m hoping I get the time to try and implement a new Content Management solution over on the PUMUG website. Moveable Type is great but it simply isn’t working out on our host CSociety. They don’t provide a suexec interface for cgi so I either have to set EXTREMELY lax permissions on the web dir or do the permissions juggle everytime someone wants to update the site ;)

My solution will probably be Text Pattern. It looks to be an awesome product and I hope that I can use it to pull directly from the db without any of this silly static content that it causing me so much anguish :P

It’s currently at version Beta 1.6.1 but it looks to be pretty polished and already have a lot of features. Anyways, that was a TOTAL BABBLEFEST. I hope everyone has a great weekend ;)