News Feed
Sections




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

PHP-Coding-Practices.com:
Composing Methods Replace Temp With Query
June 14, 2007 @ 14:25:00

In a new article from PHP-Coding-Practices.com today, Tim Koschuetzki offers a different sort of solution for working with those little temporary variables scattered throughout your code - replacing a temporary variable with a queryable structure.

When you are using a temporary variable to hold the result of an expression, extract the expression into a method. Then replace all references to the temp with the new method. The new method can then be used in other methods.

His suggestion basically replaces the quick temp variable with something slightly more complex but something that can be used anywhere in the class. He uses the example of multiplying an amount times the quantity - first just assigned to a temporary variable inside a method then refactored as the result of another method returning the same thing (but accessible from anywhere).

0 comments voice your opinion now!
temporary variable query method temporary variable query method


blog comments powered by Disqus

Similar Posts

WebReference.com: The Building Blocks: Data Types, Literals, Variables, and Constants - Part 3

Mastering Zend Framework: Building and Executing SQL Queries In Zend

DevShed: Paginating Database Records with the Code Igniter PHP Framework

Leszek Stachowski's Blog: php anachronic coding standards

Derick Rethans: No to a Uniform Variable Syntax


Community Events

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


opinion introduction conference voicesoftheelephpant configure php7 framework laravel podcast release language community interview symfony2 performance application series part2 example api

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