I dont know much about classes, but have a reasonable knowledge of PHP/MySQL.
But why should I learn classes? I know they are important but what benefits can I see using them that I cant with?
I dont know much about classes, but have a reasonable knowledge of PHP/MySQL. But
Share
Actually, I’ve found that it is often simpler to use function-based programming in php than object oriented. There are a lot of ways in which just using function libraries and trying to keep your code simple and direct make your php scripts more maintainable, especially if you minimize state to increase reproducibility.
Objects & classes are one tool that you should get to know so that you can choose between the different options, but certainly not the only choice, now that php 5.3 has first class functions, moving more in the direction of true functional programming is another tool that you could get to know.
Php’s background is very function-based, a huge portion of the native language provided is functions and sometimes the square peg of objects doesn’t fit in php’s round hole.
This certainly wouldn’t apply to Java, but php’s background is very rooted in functions.
Edit:
Let’s be clear, to be effective at php you will have to have a good grasp of objects, because you are going to encounter it frequently, and if you work for other people in php, you’ll probably have to write OO yourself on your employer’s behalf. So get to know it well. But don’t stop at OO and consider it the be-all-end-all solution. In fact, when it comes to dealing with other people’s bad php code, I have found solid function-based programming to often be a simpler tool for refactoring and cleaning up bad code.
I would say there are a few ways to write php code:
And eventually, as php 5.3 matures, we’ll be able to start throwing in a bit more functional programming into the “good function-based code” category and it will become an even more effective alternative. In the meantime, though, get comfortable with 2 and 4 because you’ll need ’em both.