Here's reason # 1001 to use a class instead of a list of functions:
A function without a class container or a namespace is kind of like a global variable. You read a passage of code, see this function, and go, whoa! where did this baby come from? Is this some new PHP function I never heard of yet? At least with a class you have some kind of understanding what it belongs with and might be able to find the class file usually.
Another Reason To Use Classes Instead of Functions
Moderator: General Moderators
Re: Another Reason To Use Classes Instead of Functions
I don't think thats a very good reason to use classes. But maybe thats why you numbered it 1,001 in your book? Where are the other 1,000? heh
functions are a language feature. I don't think a language feature is a smell, its the programmer him/herself, NOT the language that deserves the blame/credit most of the time.
A stand alone function is not always "like global data", however if that function is naturally coupled with other functions AND they share state, then you have a rational reason to use objects.
And classes that use all static members are no better then a function using globals. In fact all you did was organize your code, you change nothing about the "global" properties of it by simply moving the same function to a class.
So in short
use of functions != global data
bad programmers == use of global data in functions
use of classes != avoiding global state
functions are a language feature. I don't think a language feature is a smell, its the programmer him/herself, NOT the language that deserves the blame/credit most of the time.
A stand alone function is not always "like global data", however if that function is naturally coupled with other functions AND they share state, then you have a rational reason to use objects.
And classes that use all static members are no better then a function using globals. In fact all you did was organize your code, you change nothing about the "global" properties of it by simply moving the same function to a class.
So in short
use of functions != global data
bad programmers == use of global data in functions
use of classes != avoiding global state