måndag 13 september 2010

Object orientation vs. Procedural coding in PHP

As earlier meantioned I am currently working on a personal content management system for the purpose to show of my developer skills and to have a platform where i can create pages to show my different applications and Flash-modules for example.

This post will be about the object oriented aproach to PHP and my opinions and experiences with it as a young junior developer. An important notice before i beging is that i am not an expert in programming and all questions or opinions are welcome.

First things first: There are (As i see it) two different aporaches to PHP-programming. The first one is the procedural aporach where a PHP-file containing "bare code and functions
" are being "runned through top to bottom" when the file is requested by the system. The other aproach is the object oriented aproach (OO-aproach) where a PHP-file is written as a class and are being initiated only when the class is called as an object from another class of file.

When I took a web programming course to learn PHP at the University we learned only and just only how to write procedural code. I didn´t know that you could work with classes and objects in PHP until I worked this sommer at a company called Smelink, there I worked as a PHP programmer and our goal was to rebuild their CMS-tool to fit the modern web. The funny thing is that, according to friends and past colleagues there is a certain lack of knowledge about the OO-approach to PHP-programming in academical courses. I find this rather strange...

Anyways, i have choosen to build my content management project with object oriented PHP because it is allot easier to handle and navigate through files and code in a well structured file-system with classes. Off course, som files will have som procedural-code in it because some procedures doesn't nessecarly become more efficient as a function inside a class object.

Another reason to work with classes is that this project will grow bigger and bigger, and i will change things and build allot of new stuff along the way. This demands that i can efficiently find the code that i want and i think that an object oriented class-system will make this easier.

What do you think? Do you like an object oriented aproach to PHP or are you more old fashioned and prefers the procedural aproach?

You will here from me again soon, have a nice one.

Inga kommentarer:

Skicka en kommentar