[thelist] To class or not to class in PHP

Stephen Rider evolt_org at striderweb.com
Wed Dec 26 16:19:40 CST 2007


Hi all --

I do a decent amount of work on plugins and add-ons for the open- 
source WordPress. When working on a program that has so many "cooks",  
and that can have any number of third-party add-ons at any given  
time, I've been told that it's a smart idea to avoid function name  
conflicts in PHP by wrapping functions in a class, like so:

class myuniqueclassname {

	function function1() {...}

	function function2() {...}
}

...and calling them this way:

myuniqueclassname::function1();

So the question to the PHP gurus out there: is this a good idea or am  
I better off just prefacing my functions with something like...

function myplugin_function1() {...}

...and so forth?

Is wrapping code in a class more "expensive" in terms of execution  
and memory?  are there other issues I should know about?

Any advice appreciated.

Regards,
Stephen



More information about the thelist mailing list