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

IBM developerWorks:
Five good programming habits in PHP
Dec 04, 2008 @ 18:04:56

Nathan Good has posted five tips PHP developers should use in their work to develop good programming habits to the IBM developerWorks site today.

Just like any language, developers can write code in PHP that ranges in quality from truly awful to very good. Learn good programming habits that can help you bridge the productivity gap. [...] Bad coding habits seem to accompany defects in code and can cause code to be difficult to change without introducing new defects. The following five good habits, when applied to your PHP code, will help you avoid these pitfalls.

Here's the list:

  • Use good naming.
  • Take smaller bites.
  • Document your code.
  • Handle error conditions.
  • Never, ever, copy and paste.
tagged: programming habit bestpractice document naming error copynpaste

Link:

IBM developerWorks:
Build seven good object-oriented habits in PHP
Oct 31, 2008 @ 12:51:59

The IBM developerWorks website has a few suggestions - seven of them, in fact - that they think can help make you a better PHP programmer.

With PHP's object-oriented (OO) language features, if you aren't already creating your applications with OO principles in mind, these seven habits will help you get started in the transition between procedural programming and OO programming.

Each of the seven OOP habits have more details below them, but here's the short list:

  • Be modest.
  • Be a good neighbor.
  • Avoid looking at Medusa.
  • Embrace the weakest link.
  • You're rubber; I'm glue.
  • Keep it in the family.
  • Think in patterns.

In each there's a "bad habit" and a "good habit" to explain the concept a bit more fully, everything from error handling to interfaces.

tagged: oop objectoriented tutorial seven habit pattern error handling cohesion

Link:

IBM DeveloperWorks:
Seven habits for writing secure PHP applications
Oct 01, 2008 @ 15:28:55

The IBM DeveloperWorks site has posted some advice that can help keep you, your application and your data safe from security-related attacks.

Security in a PHP application includes remote and local security concerns. Discover the habits PHP developers should get into to implement Web applications that have both characteristics.

The habits in their list are:

  • Validate input
  • Guard your file system
  • Guard your database
  • Guard your session
  • Guard against XSS vulnerabilities
  • Guard against invalid posts
  • Protect against CSRF

Each comes with their own explanation and for some, code to help you spot the mistakes and correct them.

tagged: habit security application validate guard file database xss csrf

Link:

Joakim Nygard's Blog:
Optimizing PHP Through Habits
Apr 25, 2007 @ 15:39:00

Spurred on by some previous benchmarks [pdf] from Ilia Alshanetsky, Joakim Nygard decided to run some his own benchmarks on the same sort of functionality.

There are numerous discussions in the blogosphere about whether to use echo versus print, if for() is faster than while(), etc. and though the gains are usually very small, I decided to add my thoughts to the debate. I found an article on optimization through coding habits in Ilia Alshanetsky's zend performance slides.

According to his results:

  • Calling require_once() 10000 times in a for() loop with an empty file is 4x faster.
  • With a simply autoload requiring a class and 10000 loops of new Foo() versus require_once('foo.php'); new Foo() shows that __autoload() is ~3.7 times faster.
  • If a class method can be static, declare it static. Speed improvement is by a factor of 4.
  • Avoid function calls within for() loop control blocks
  • Always, always quote array keys.
  • Get rid of 'harmless' error messages - they take time to generate and output.

I am not out to prove Ilia wrong - he knows PHP better than most - and for all I know, they could have optimized those very functions in PHP 5.2. [...] It would appear that there are improvements, albeit small, to achieve from minimal effort. Plus I was surprised by the discrepancies I found compared to Ilia's recommendations.
tagged: optimize coding habit benchmark requireonce autoload loop optimize coding habit benchmark requireonce autoload loop

Link:

Joakim Nygard's Blog:
Optimizing PHP Through Habits
Apr 25, 2007 @ 15:39:00

Spurred on by some previous benchmarks [pdf] from Ilia Alshanetsky, Joakim Nygard decided to run some his own benchmarks on the same sort of functionality.

There are numerous discussions in the blogosphere about whether to use echo versus print, if for() is faster than while(), etc. and though the gains are usually very small, I decided to add my thoughts to the debate. I found an article on optimization through coding habits in Ilia Alshanetsky's zend performance slides.

According to his results:

  • Calling require_once() 10000 times in a for() loop with an empty file is 4x faster.
  • With a simply autoload requiring a class and 10000 loops of new Foo() versus require_once('foo.php'); new Foo() shows that __autoload() is ~3.7 times faster.
  • If a class method can be static, declare it static. Speed improvement is by a factor of 4.
  • Avoid function calls within for() loop control blocks
  • Always, always quote array keys.
  • Get rid of 'harmless' error messages - they take time to generate and output.

I am not out to prove Ilia wrong - he knows PHP better than most - and for all I know, they could have optimized those very functions in PHP 5.2. [...] It would appear that there are improvements, albeit small, to achieve from minimal effort. Plus I was surprised by the discrepancies I found compared to Ilia's recommendations.
tagged: optimize coding habit benchmark requireonce autoload loop optimize coding habit benchmark requireonce autoload loop

Link:


Trending Topics: