PHP - is this bad practice?

Soldato
Joined
8 Oct 2005
Posts
4,185
Location
Midlands, UK
Hi,

For a lot of my old projects I used a simple class called Tools, with static methods for things like filter input and other basic, common tasks. I'd include this class on the desired page. If I wanted to call one of the classes methods I'd then do Tools::somemethod();

Is this really bad practice? Only reason I ask is because a customers relative is apparently a 'top' php developer and pointed out that uses classes in this way is seriously bad practice. The customer is a bit concerned.

Have I dropped a ball here?

Thanks
 
Soldato
Joined
26 Dec 2003
Posts
16,522
Location
London
They're called utility classes, and I don't think anyone worth their salt thinks of them as inherently bad—especially in a language like PHP, which lacks the ability to monkeypatch. Ignore the guy.
 
Associate
Joined
5 Feb 2009
Posts
424
Tell your customer to stop being concerned and go read Joel Spolsky's blog dated 23 Sept. I do hate this sort of thing. Tell them next time you'll double the cost and do it according to 'best practice'.
 
Soldato
Joined
28 Aug 2006
Posts
2,980
Nope its not bad practice. We call those types of classes Static Helper Classes.

The only bad thing is it goes against Class ideaology. I.E. a class is supposed to represent a single entity. Eg. A Customer Class.

To get away from this. Your helper functions could just be a group of functions in an SSI.
 
Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
No, it's not bad practice at all. However, as djkav said, it does somewhat oppose OOP principles.

Strictly speaking, the correct way to separate utility functions from the rest of your code is to use namespaces, though these have only been supported since 5.3.

Tell your customer to stop being concerned and go read Joel Spolsky's blog dated 23 Sept. I do hate this sort of thing. Tell them next time you'll double the cost and do it according to 'best practice'.

He almost seems to be advocating writing sloppy code simply to get the job done more quickly. While spending days agonizing over how to organize your utility functions is clearly senseless, good design shouldn't be neglected.
 
Last edited:
Associate
Joined
5 Feb 2009
Posts
424
He almost seems to be advocating writing sloppy code simply to get the job done more quickly. While spending days agonizing over how to organize your utility functions is clearly senseless, good design shouldn't be neglected.

I disagree. I not saying don't be organised, but he is saying don't over complicate things.
 
Soldato
OP
Joined
8 Oct 2005
Posts
4,185
Location
Midlands, UK
Right, have decided to toptally ignore anything this tool says from now on as he's just been on the phone to me. He said he'd been looking over the source code the site and noticed another 'issue' as he put it.

Told me when I'm outputting options for a drop down I should be using a tab (\t) and not just a new line (\n) for each option (yes, he thought this required a phone call). Okay, so the select options are aligned to the far left whern you view the page source from your browser, this makes bugger all difference to anything.
 
Man of Honour
Joined
31 Jan 2004
Posts
16,330
Location
Plymouth
That's the kind of thing which requires a red-flagged e-mail with URGENT in the subject line first, I hope he gave you a warning before the followup call?

:(
 
Caporegime
Joined
18 Oct 2002
Posts
29,388
Location
Back in East London
Quick, set up a conference call with all parties involved and debate this meaningful and significant problem of tabs vs newlines.

Hell.. if it were me developing it, he'd be lucky to get any white space at all in the mark-up :p
 
Top Bottom