Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-21-2012, 01:07 AM   PM User | #1
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
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?
angelali is offline   Reply With Quote
Old 11-21-2012, 01:42 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 11-21-2012, 02:39 AM   PM User | #3
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
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.
Custard7A is offline   Reply With Quote
Old 11-21-2012, 03:21 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-21-2012, 03:41 AM   PM User | #5
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
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.
angelali is offline   Reply With Quote
Old 11-21-2012, 06:53 AM   PM User | #6
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,907
Thanks: 10
Thanked 293 Times in 289 Posts
Dormilich is on a distinguished road
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.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 11-21-2012, 09:11 AM   PM User | #7
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Even JavaScript uses a weak OO.
angelali is offline   Reply With Quote
Old 11-21-2012, 02:28 PM   PM User | #8
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,942
Thanks: 7
Thanked 82 Times in 81 Posts
firepages will become famous soon enough
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.

Quote:
...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)
firepages is offline   Reply With Quote
Old 11-21-2012, 02:46 PM   PM User | #9
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
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!
angelali is offline   Reply With Quote
Old 11-21-2012, 04:08 PM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-21-2012, 04:14 PM   PM User | #11
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,942
Thanks: 7
Thanked 82 Times in 81 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Old 11-21-2012, 04:21 PM   PM User | #12
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
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?
angelali is offline   Reply With Quote
Old 11-21-2012, 04:29 PM   PM User | #13
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,942
Thanks: 7
Thanked 82 Times in 81 Posts
firepages will become famous soon enough
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)
__________________
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)

Last edited by firepages; 11-21-2012 at 04:32 PM..
firepages is offline   Reply With Quote
Old 11-21-2012, 05:06 PM   PM User | #14
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-21-2012, 05:09 PM   PM User | #15
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 46
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 AM.


Advertisement
Log in to turn off these ads.