Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts

    PHP OO or Procedural

    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?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,631
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    Quote Originally Posted by angelali View Post
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    Even JavaScript uses a weak OO.

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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
    <?php
    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.

    Quote Originally Posted by angelali View Post
    ......

    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    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!

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Quote Originally Posted by angelali View Post
    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.

    Quote Originally Posted by angelali View Post
    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 ?

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

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #12
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts
    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?

  • #13
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    Quote Originally Posted by angelali View Post
    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.

    Edit:
    BTW I use smarty 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)
    Last edited by firepages; 11-21-2012 at 04:32 PM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •