View Full Version : PHP OO or Procedural

11-21-2012, 02:07 AM
Well, I am not a programmer. I have a diploma in IT but not in computer science field. I am more like a designer but I know some server side stuffs like MySQL and PHP (Procedural).

I am making a website where people will share texts. There will be registration and login, then the user account where the user can edit his/her account settings and delete his/her text uploaded if he/she wants. There will be a form to post the texts. There will be a pagination. Of course, all will be in database and with security.

I know many will say OO is better etc...bla bla bla. But the website I will make is not huge or complex like Facebook, Amazon or even other bulky websites. So, I can go with Procedural? By the way, Procedural is not dead, in fact it is still used more on medium-sized application. It is not a matter I do not want to learn OO, but, the website I am doing is not huge at all! Some functions that's all, and I dont have an issue to update the codes. In fact, it will not be updated too much.

Your opinion?

11-21-2012, 02:42 AM
I generally use a mix of both. I use objects where it makes sense to do so and use procedural code where objects would be overkill.

11-21-2012, 03:39 AM
I really enjoy using object-oriented over procedural; It has more tools for the developer in specific, such as autoloading, templates, or visibility. These things allow for better script structure. However, since most (as far as I've seen) of the benefits given by OO are internal, the result shouldn't particularly suffer depending on if you use procedural or OO.

I think the only consideration here is which you are more comfortable using.

11-21-2012, 04:21 AM
No matter what, you'll need at least one procedural call in PHP since there is no overridable main method to execute.
Answer: use what you want to use. I'm an OO developer, but for every feature gained in OO you will lose something from procedural. Its a constant tradeoff.
Choose OO if you want to centralize your control, add reusability and extendability. Use procedural if you want to minimize the overall footprint in both memory and storage. Overall procedural is typically far less code to perform the same task as OO will be; one of the exceptions I can think of is performing functional privacy control in a system that allows many developers to add to. This is much easier to do in OO than in procedural code to control privacy leaks between "objects", and its bloody hard to do properly in procedural.

Sounds to me like you want to use procedural programming. And no, procedural is not (and IMO hopefully never will be) dead. There are pros and cons to both paradigms, but the paradigm is a tool and just like anything with programming you choose the best tools to do the job.

11-21-2012, 04:41 AM
I have worked many stuffs in procedural including security. As I am not a programmer (I am more on design), I dont know why I should care mastering myself on OO.

Yes, I will learn some classes, to gain knowledge and to practice but as I am creating a medium-sized website, I think procedural will be OK. Perhaps I will add some classes, but this does not mean it will be fully OO. Putting classes in your codes is not OO. OO sucks!

Moreover, I have heard PHP OO is not the REAL OO like other OO born languages! Don't know why the hell they made an OO version. It is crystal clear how poor the language is from this, I mean weak. I bet if major CMS were not in PHP, Ruby would beat it or Python.

And yes, if we give all websites in PHP OO a figure of 100%, I bet not even more than 20% are pure OO or good written OO. We have more amateurs, noobs, and big headed who do OO programming I noticed.

I am so sad ColdFusion died... The only best and easiest language... More easy than PHP in many aspects and robust as well than it.

11-21-2012, 07:53 AM
Moreover, I have heard PHP OO is not the REAL OO like other OO born languages! Don't know why the hell they made an OO version.

so OO has finally become a feature set of a language? personally, Iíll stick to OO being a paradigm and happily apply it to PHP or JavaScript or whatever language uses objects.

11-21-2012, 10:11 AM
Even JavaScript uses a weak OO.

11-21-2012, 03:28 PM
Sounds to me like you are trying to convince yourself not to use OO and want help ;)

Not that long ago I was in a similar state, these days however...
even when I try NOT to use OO these days I always fail miserably, even when I have a quick and dirty task to do I always seems to start with
class .. ;)

the why I do that is the reuse .. yes you can reuse functions and in truth unless you are really pedantic about how you use OO in PHP its not always quite as reusable as one may wish .. but it wins bigtime, even for a sloppy coder like me.

...Ruby would beat it or Python

Python maybe (if you are google), ROR sorry, failing to scale (miserably), and thats the beauty of PHP's 'looser' OO implementation and the ability to easily and freely mix procedural and OO

& no its not as complete an implementation as say Java,
you can slow PHP down to a Java slog if you create a Java like implementation ... but then you may as well use Java which is slow and steady but does scale.


I am so sad ColdFusion died... The only best and easiest language... More easy than PHP in many aspects and robust as well than it.

easy, perhaps, robust .. to its limitations, otherwise, not even close,
we use PHP for web-stuff, IPC, printing barcodes, stocktakes, managing remote systems, for virus removal, I am naf at bash/perl so all the cron jobs are in (or converted to) PHP, the list is endless (well not quite, tried to write a driver in PHP but failed miserably :( )

Anyway, as Fou-Lou said , use whichever you are more comfortable with, but please don't blame PHP for your preference to not use it ;)

11-21-2012, 03:46 PM
It is not a question to blame or not. Many advanced programmers, who code modules for Drupal for example, told me OO really sucks in PHP.

With these frameworks, beginners are confused what to use. Some say Zend is better, some say CodeIgniter, some say Symphony, other who are more big-headed will say the terrible Yii, which is which?

Yes, you can learn one framework and dont care the rest, but when you search for jobs, some are using Yii, others are using Zend bla bla bla, this makes you angry and you have to learn more.

Take example of JavaScript, I support JQuery as framework, but you have new frameworks like CoffeeScript etc... Fortunately, these new frameworks are not popular as much as JQuery. Even frameworks which are before JQuery are dying slowly like Mootools and Dojo, but what will happen if companies start using more than 3 frameworks as example? You are doomed to study forever!

Look Ruby, it has its beautiful Rail as framework and its sufficient. ColdFusion I think does not have, not sure yet, never heard. ASP.Net is already a framework which uses C# sand VB.Net. These languages are real OO as well in front of PHP. It is them which must take the credit. PHP became popular just because it is easy, and THANK to Procedural first for making it popular, not OO!

11-21-2012, 05:08 PM
Your mistaking poor application interfacing for poor OO implementation. If someone is having issues with code modules in an OO application it means either that a) the application is not interfaced properly for extendability, b) the application is not designed to be extended in this manner (by design), or c) the programmers are not as advanced as they claim.

There is nothing wrong with PHP's OO implementation. Sure, it has its bugs and limitations, but every language does. No it won't be comparable to C#, Java, or C++, but these languages are all [mostly] OO native and neither can compare to each other either (mostly as they are not listed as pure). . Hence choosing the tool to do the job.
PHP's primary limitation with its OO engine API is that it is highly unstable between versions 5.0 and 5.3. One has to pay very close attention to the changes implemented between these versions to determine if the standard approach needs to be modified. 5.3 added namespacing and late static binding bringing it more in line with typical OO concepts (not necessarily the OO paradigm).
PHP's primary weakness still hinges on the core since PHPT and was adopted by Zend when they took over the PHP/FI for 3.0 development. And that is the datatype weakness pulled from the PERL language.

If your interesting in studying the OO of PHP, start with a more suitable OO language (no, I wouldn't suggest that PHP is the language to learn on, either procedurally or OO specifically due to PHP's inherent datatype weakness). I'd suggest C# or Java as the best two as PHP reflects many of its features from these languages. Knowing that PHP is a datatype weak language, when compared to Java or C# you remove the ability to handle datatype levels which includes the method signature (including overloads), and generics. What you pretty much have left over is PHP OO. Knowing PHP OO now allows you to interact properly in an OO designed environment. I don't program for any of these frameworks, but if I decided to it would take minimal time to study the API to know what I have to do.

11-21-2012, 05:14 PM
who code modules for Drupal for example, told me OO really sucks in PHP.

err perhaps its Drupals implementation of PHP OO that sucks.. I don't know, never used it but most of the large frameworks suck to one extent or another and often this comes from trying to be Java which as I said before I personally think is pointless (read my sig)
Its a bit like saying javascript sucks cos if don't like jQuery.

It is them which must take the credit. PHP became popular just because it is easy, and THANK to Procedural first for making it popular, not OO!

As a user of PHP from PHP2 F/I when PHP really meant `personal home page` I have to suggest (in the nicest possible way) that you are speaking out of the wrong end of your body ;)

Yes PHP is easy at a basic level, PHP was created to solve the 'web problem' which was basically PERL at the time which with all respect to PERL ninjas is often far too much like sanscript for mere mortals.
The reason for PHP's explosion and an explosion it was, was that it was not only easy (like CF) but also very powerful and could do so so much more that personal home pages.
It is an interpreted language of course and as such has some limitations (and of course advantages) though nowadays these are negated by opcaches and the like.

+ if you don't want to use OO then what does it matter which OO language you are not going to use ?

doh. Fou-Lou got in before me and as usual put it far better than I did :(

11-21-2012, 05:21 PM
I will start learning the basic of OO. Classes stuffs etc.. But as I said, I am not a programmer, I am more on design (Front-end). So, I dont care about OO too much.

Why we use framework in PHP and not pure OO?

11-21-2012, 05:29 PM
Why we use framework in PHP and not pure OO?

Again, up to you how you go about it.
If you do enough OO you end up with your own framework anyway at some point, or you can start with an existing one.

I roll my own, but do use a few Zend modules (PDF ,mail, Barcode) without actually using the framework as a whole.

BTW I use smarty (http://www.smarty.net/) a lot these days, if design is more your thing then a template engine like smarty (and thats just my favorite) makes it so easy to separate the design from the rest of the code (and its OO)

11-21-2012, 06:06 PM
A framework doesn't dictate which paradigm will be used either. I can create a framework that uses either procedural or OO code, but when it comes to frameworks I'd suggest OO is easier to implement to control privacy leaking between the code. Its not impossible to perform on procedural, not in the least, but it is more complex since you cannot effectively "own" things. So if I present a function in procedural, anything that loads that definition can make use of that function, and has to be controlled within the function itself via backtracing. OO on the other hand can provide a scope and owning class, so only objects of this type can access this function, and everything else has to use these functions I provide it. Reflection, interfacing, and (5.4+) traits also works wonders for code reuse and compact construction.

Since you would like to study OOP, then I will suggest one thing regardless of the language you choose (except C++). implements if far more valuable than extends. Extends has its purposes, and ultimately you can end up with a class that simply extends another, but for multiple inheritance whether on a concrete or abstract class than implements is required. Use abstracts as necessary to create the template up to the point you are satisfied it is still abstract but minimizes the required code for implementation.

11-21-2012, 06:09 PM
Gotta be honest I've never touched OOP with php and I'm not that keen on the idea either.

For a start, I still see objects as objects you place on a form like in many windows languages. Those are (IMO) true objects. In PHP it's just another file to be included with a bunch of internal functions and it's own memory.

Secondly PHP are known to change the way OOP works between versions. V4 would call the same function as the objects name to create the object, I believe in V5 it calls __construct() ? - If the goalposts are going to keep moving then perhaps you should play baseball instead - thats my opinion anyway.

11-21-2012, 06:19 PM
4.0 isn't really an OO engine. It was a hacky addin to the existing 4.x procedural core. It is. . . not great to say the least, but for what they could do it turned out surprisingly well (no, I wouldn't use it either :P). 5.0 redefined the entire underlying engine for OO making it far more powerful. 4.x was more of a collection of functions and variables specific to a "group", or more close to a struct than an object.
Constructor name is often the name of the class. I haven't a clue why they redefined that in 5.x especially since the BC for 5 to 4 still dictates you can use them with the exception of namespaces matching the same classname for the ending portion of the namespace.
This is another great reason to not use PHP as your language of choice to learn OOP on.

11-21-2012, 07:26 PM
This is another great reason to not use PHP as your language of choice to learn OOP on.

Heh, that says it all for me :D

11-21-2012, 07:29 PM
When WordPress was released, it was 99% procedural! I have not downloaded the last version, I don't know if they have switched to OO.

Every crap you will do in OO can be done in Procedural except it can be more complicated or can be too long, but still you can do it!

11-21-2012, 07:49 PM
Not even. Most of the time procedural will be less footprint and easier to perform the same task. One of the few exceptions is the privacy control which is quite complex to do in procedural. But you do take the tradeoff of re-usability, so you have to weigh which is more important to you.
OO is a good choice for a shared system that unknown individuals could add onto. This grants me control which is difficult to implement in procedural, and if implemented improperly can result in many bugs introduced by addon code that is difficult to debug.

11-21-2012, 07:52 PM
Who made PHP OO? Zend team or Lerdorf?

11-21-2012, 08:01 PM
PHP OO is developed by Zend. AFAIK Rasmus is still on the development team, but I'm not sure if he's actively participating or just consulting.

11-21-2012, 08:02 PM
Damn Zend!

11-22-2012, 08:01 AM
The blithering fools!

Lol, just go use procedural and stop whining.

11-22-2012, 09:54 AM
OO was introduced in PHP3 though internally it was not true OO of any description just emulation of objects, Zend changed this and it grows with every version.
Lerdorf is not a gigantic fan of OO ala MVC etc

11-22-2012, 10:36 AM
Lerdorf is not a gigantic fan of OO ala MVC etc


11-22-2012, 02:28 PM
Read my sig ;)

11-22-2012, 03:22 PM
So this guy does not like MVC? And moreover, in which year he made the statement?

11-23-2012, 12:23 AM
2006, in Zagreb , I don't know what he was wearing though ;)

11-23-2012, 11:10 PM
I think some of you guys have already said this with other words. But I think that when it comes to PHP and the choice of OO or Procedural you should really go with what you're most comfortable with. For example if you've for example been working a lot with C or any other procedural programming language you will probably find it more comfortable to keep using the same methods. And that's completely okay, because as many of you have already written there is not downside in performance when it comes to using procedural language. And according to me many well-commented procedural scripts are often easier to understand that mediocre OO-scripts.

Though if you're and hardcore Java programmer you might prefer the OO-way. And then that's definately the way to go as you will feel more comfortable with that. If you're a newbie; well then just go with what feels best for you. Try some OO-programming and see if you like it.

Personally I'm mainly working with procedural PHP code. Though I'm aware of some of the advantages of OO. And if I run into a problem which would be much easier to solve with OO programming, well then I'll do that.

Just don't feel like you have to choose a specific side in this ever lasting battle. Just follow your heart ;)