News Feed
Sections




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

DZone.com:
Practical PHP Refactoring Encapsulate Downcast (and Wrapping)
November 04, 2013 @ 12:44:06

On DZone.com Giorgio Sironi has posted a refactoring recommendation around the handling of the data and types in your PHP code. He suggests the move from just a simple variable to a Value Object (noting that it's not really needed in PHP, but can provide a "richer interface" to work with the data).

Statically typed languages sometimes encounter the problem of downcasting: the compiler is only able to guarantee a basic type, and the object contained instead is an instance of a richer subtype. [...] You'll never need to downcast objects: variables can contain handlers to objects or even scalars without compile-time checks. Casting with (ClassName) is not even supported by the language (while casting a non-object with (object) will give you a stdClass.)

He starts by talking about scalar values in PHP and a simple form of downcasting - using the casting notation included in the language. From there he moves into the conversion into Value Objects and some of the updates (like docblocks) that would come with their use. He outlines some steps towards the conversion and provides an example set of scripts showing the conversion process.

0 comments voice your opinion now!
refactor scalara value variable valueobject downcast

Link: http://css.dzone.com/articles/practical-php-refactoring-38

blog comments powered by Disqus

Similar Posts

NetTuts.com: Refactoring Legacy Code: Part 4 - Our First Unit Tests

Till Klampaeckel's Blog: Zend Framework: Writing an IN-Clause with Zend_Db

DZone.com: Practical PHP Refactoring: Encapsulate Downcast (and Wrapping)

Chris Roane's Blog: Analyzing the Value of a PHP Programmer

Felix Geisendorfer's Blog: Test Driven Development in Real World Apps


Community Events





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


framework list interview community language release introduction opinion testing symfony2 series api podcast developer code unittest threedevsandamaybe install refactor laravel

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