Class or just an include?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
bobbyaa
Forum Newbie
Posts: 17
Joined: Wed Oct 13, 2004 4:54 pm

Class or just an include?

Post by bobbyaa »

What's your opinions on header/footer templates. Would it be more efficient to generate a class that has them and pass the variables like title, etc? Or is it more efficient/easier to just create the pages and include those pages?

Thanks,
Robert
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Depends on the scope of your application. If the header and footer would always be the same, have a static include.
If it needs to be done dynamically use a function.
If you need to filter HTTP request, or access the database or, more general, process the some data (as in modify data), use a class.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I'd say a Class no matter, but that's cause I love OOP. ;)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Yeah i follow in Sami's footsteps - Always a class for anything larger than say just printing text to the screen. It makes you group all the related functions and have a completly self-contained unit that you can use on other projects.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

3 cheers for classes! HIP HIP HURRAY!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

I don't want to bring up that old function vs class discussion at all, but to blindly vote for OOP for something as simple as an include is somewhat one-eyed. It depends entirely on the scope and purpose of the application. Perhaps bobbyaa could shed some light on what he wants to do and what it's for.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I agree with patrikG, if you have simple headers and footers just include them. If you need encapsulation, inheritance, etc. then use a class.
Post Reply