Page 1 of 1

OOP Vs Procedural style

Posted: Tue Mar 09, 2010 3:10 am
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!

Re: OOP Vs Procedural style

Posted: Tue Mar 09, 2010 3:48 am
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.

Re: OOP Vs Procedural style

Posted: Tue Mar 09, 2010 5:29 am
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

Re: OOP Vs Procedural style

Posted: Tue Mar 09, 2010 11:27 pm
by realnsleo
thanks a lot guys! this really helps!!!

Re: OOP Vs Procedural style

Posted: Wed Mar 10, 2010 12:35 am
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.