OOP Vs Procedural style

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
realnsleo
Forum Newbie
Posts: 15
Joined: Sat May 16, 2009 12:08 pm

OOP Vs Procedural style

Post by realnsleo »

Hi all,
i'm developing some kind of profile system for an organization that will have pages like index, login, profile, inbox and so on. i want to combine a mixture of oop and procedural style programming in php. i have decided to use oop in creating objects for example users, and database connection.
i dont know whether i should also make a page object or just hardcode header and footer files into the different pages. for example if i hardcode this is how my files will appear:

Code: Select all

<?php include("header.php") ?>
 
<div class='container'>
     // Content goes here
</div>
 
<?php include("footer.php") ?>
however if i use oop in my templating it will appear:

Code: Select all

<?php
 
     $page = new page($page_variables);
     $page->displayHeader($header_variables);
     $page->displayBody('<div class="container"></div>');
     $page->displayFooter($footer_variables);
 
?>
what do u suggest would be the best practice or what would you recommend? Thanks!
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: OOP Vs Procedural style

Post by papa »

When it comes to headers and footers, they don't change much according to my experience. Usually it's enough to just include your headers. And if needed make a couple of extra ones. Might be you wan't to add some JS to the header or something.

I also usually have a $title var in my header file that i change dynamically.

Might be a little overkill to oop that.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: OOP Vs Procedural style

Post by s.dot »

It is up to you. :)
If I were working on the code and it were readable and understandable, i couldn't give two hoots if it were oop or procedural or a mixture :D
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
realnsleo
Forum Newbie
Posts: 15
Joined: Sat May 16, 2009 12:08 pm

Re: OOP Vs Procedural style

Post by realnsleo »

thanks a lot guys! this really helps!!!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: OOP Vs Procedural style

Post by Christopher »

Unfortunately neither of your examples is OO ... even if your second example is using the class construct. I would recommend looking at modern PHP frameworks that tend to use a Model object injected into a View object that renders a template which can dynamically load View Helpers.
(#10850)
Post Reply