News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Reddit.com:
Is there anything wrong with using functions?
August 07, 2013 @ 11:39:47

In a largely object-oriented world, one Redditer asks if it's still okay to just use functions, the more procedural method of PHP development:

Is there anything wrong with using an include file of functions instead of using full code in a file? [...] Obviously you wouldn't write functions for one off tiny things, but I think it would help to read files altogether especially if the functions file was alphabetically listed.

There's several suggestions in the comments including things like:

  • You should also look into using a templating engine, so you can separate your html from your php code.
  • One thing you could always ask yourself is "Do I will ever need to write that part a second time somewhere else ?" If "yes", that means you should put that part in a function.
  • Before you go writing a load of functions and putting them all in a file, which can get quite unmanageable, consider grouping them logically and placing them in classes.
  • Function names should start with a verb though (except for trivial getters whose meaning is clear by context, which can be named after the thing they get).
  • Do group them logically, but it's not necessary to place them in a class unless they share data or state.
0 comments voice your opinion now!
oop functions procedural opinion file group

Link: http://www.reddit.com/r/PHP/comments/1jss6q/is_there_anything_wrong_with_using_functions

blog comments powered by Disqus

Similar Posts

SitePoint PHP Blog: Best PHP Frameworks for 2014

DevShed: Handling File Data with the Facade Pattern in PHP 5

Zend Developer Zone: File uploads with Adobe Flex and Zend AMF

PHPClasses.org: File upload progress meter for PHP 4, at last!

Perforce Software: Seven Pillars of Pretty Code


Community Events





Don't see your event here?
Let us know!


tips threedevsandamaybe release community conference application podcast interview list deployment series development framework developer language laravel api code introduction zendserver

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework