News Feed
Sections




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

Tim Koschuetzki's Blog:
Composing Methods Remove Assignments to Parameters
July 06, 2007 @ 10:21:00

In another part of his "Composing Methods" series, Tim Koschuetzki posts about removing assignments to parameters today - working with a temporary variable inside a method rather than the actual passed in value.

When your code assigns to a parameter in a function/method, use a temporary variable instead. [...] It will make your code much more readable and prevents by-reference confusion and therefore big problems in the future.

His example code uses the illustration of calling a price() method in a class to modify the inputVal value based on other inputted information. His suggestion is to not work with the actual inputVal value passed in (so as to avoid issues if it happens to be passed my reference later), but to work with a temporary variable - $result - inside the method.

1 comment voice your opinion now!
method compose remove assignment parameter temporary variable method compose remove assignment parameter temporary variable


blog comments powered by Disqus

Similar Posts

Andreas Gohr's Blog: Working with Password Hashes in PHP

PHP-Coding-Practices.com: Composing Methods: Split Temporary Variable

Mike Naberezny's Blog: Better PHPUnit Group Annotations

Leonid Mamchenkov's Blog: Perl vs. PHP : variable scoping

Kevin Schroeder's Blog: Remote Debugging with the Zend Debugger and PHPUnit


Community Events

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


opinion community extension conference interview series language laravel introduction psr7 development release podcast library video laravel5 api framework voicesoftheelephpant unittest

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