PHP-Coding-Practices.com: Composing Methods: Replace Temp With Query
600035
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).
104466
Matthew Turland has mentioned his article in the latest issue of php|architect magazine (the December 2007 issue) covering web scraping.   Just a quick post to announce (albeit a little late) that the December 2007 issue of php|architect, which includes my article on web scraping. Please buy a copy, give it a read, and feel free to post comments on the forum thread for the article. I'd love to hear some reader feedback!   Other articles in the issue include "Writing an Object/Relational Mapper in PHP", "Understanding CLI" and the cover story "Going native with mysqlnd".
607777
Sometimes developers just don't think about how much trouble they'd cause with a rewrite of existing software. They think that moving up to the latest and greatest is the way to go, and that it makes perfect sense to say out with the old and in with the new. Aaron Wormus disagrees. Well, sometimes - it depends on the circumstances, really.   At ZendCon I talked about "Planning a PHP 4 to PHP 5 codebase rewrite, a practical approach". The talk was based on my own experience, as well as famous discussion of the topic such as Joel Spolsky's "Things you should never do" and the examination of "famous" platform rewrites.   Aaron gives an example of a large company making a move from a COBOL system out to C for a mission critical system. Based on his tale, they didn't put the thought needed into making this move - new development time, keeping old developers on staff, etc - besides the fact that customers don't like change and making a move to another platform is almost definitely going to be noticed by them.
277304
The results from the latest poll conducted by the International PHP Magazine have been released. This time, they asked developers what they thought was the best way to do QA for their PHP applications.   Among the options were things like "Do API documentation", "Use code analyzers that check CS violations, XSS or SQL injection attacks" and the number one choice - "Do unit tests using PHPUnit or phpt". Three other options followed behind (using debugging tools, code analyzers and having a commit mailing list) with the API documentation falling down in last place.   They already started up this week's poll too. This time, they ask developers to vote on which of the options make for good PHP code. There's four options - structured, consistent, portable and secure. Get your vote in today!
660553
DevShed continues their series looking at connecting a PHP5 script to the powerful Yahoo! search backend with part four of the series today. This part focuses on reworking some of the previous examples to make them more modular using custom defined functions.   Logically, these examples can be really useful for learning the basic concepts surrounding the use of these search services, but undoubtedly, it's necessary to modify and improve their source code to make it more compact and completely reusable.   They start the overhaul with the web search (complete with example results) then push on to the video and image searches and work them over the same way.
416901
Aaron Wormus has a new note on his blog today about his presentation at this year's Zend/PHP Conference & Expo and another speaker he's excited to hear.    One of the Zend conference sessions that I'm pretty excited about is Don Samisa Abeysinghe's (of WSO2) "Fully Fletched Web Services with PHP".   I'll be presenting a session on "Moving to PHP5 with Style." This tutorial/case study will be based on experience in transitioning several codebases from PHP4 to PHP5, creating unit tests & started a move towards a service based architecture without a complete platform rewrite.    Aaron's talk fits under the banner of the "PHP Development" talks, including others on topics like hosting PHP applications on Windows, working with PDO, unicoding in PHP6, and using PHPUnit.
246639
In his continuing effort to redesign his blog, Shiflett.org, he's been working on one of the things that really makes a blog useful - the commenting system. Specifically, he wants site visitors to be able to add their own code listings to the comments they post. He gives more detail in this new post.   I've been playing with this tonight. Feel free to follow along as I go. The first thing you want to do is create an ordered list from the code you want to format ($code in these examples).   He gives an example of a listing using his system and explains how it all works. It's a mixture of:  PHP for parsing the data inside the 'code' tags CSS to correctly style the information, whitespace and all Some ini settings to set parameters for... ...the use of highlight string on the PHP code contents  A little str_replace magic later and you have list items styled as code blocks on your page. Check out his demo for an example.
192641
DevShed has posted the second and last part of a series of two articles based around the Composite design pattern - using it to work with strings in PHP5.   Are you a PHP developer who wants to improve your skills in pattern-based programming in PHP? If the answer to this question is a emphatic yes, then you should begin reading this article now! Welcome to the final part of the series "Implementing the composite pattern with PHP 5." Comprised of two instructive tutorials, this series walks you through the basic concepts of this important design pattern, and shows you how to apply it with some educational examples.   They start by defining a simple StringProcessor class as an abstract interface to build from. From there, they create two other classes - the SingleStringProcessor and the MultipleStringProcessor. Each of these takes in either a single file or multiple filenames and spits back out the value of the string and the length of the string.
298536
http://www.phpdeveloper.org/form/view/type/addnews PHPDeveloper.org: PHP News, Views, and Community In a new post Paul Jones points out some of the new behaviors that the extension is showing in the latest of the PHP 5 seres (version 5.2).   He starts with a code example that would work with a previous version of PHP/PDO that would allow for the binding of a single value to multiple places in the SQL statement. But:   Sadly, this is no longer the case in PHP 5.2.1. For valid reasons of security and stability in memory handling, as noted to me by Wez Furlong, the above behavior is no longer supported. That is, you cannot bind a single parameter or value to multiple identical placeholders in a statement. If you try it, PDO will throw an exception or raise an error, and will not execute the query. In short, you now need to match exactly the number of bound parameters or values with the number of placeholders.   Unfortunately, this is used quite often in Paul's Solar framework, so an update to the Solar_Sql_Adapter::query() method has had to been made to allow for the binding of multiple items automatically. It works by incrementing the bind location (like ":foo") with numbers at the end - simple and effective - and you can still pass an array to it and have it automagically work.
542657
In a new post today, Maggie Nelson starts with the wrong way to do something - passing an array from PHP to a database - and works backward to make it all right.   It would be really useful to have an easy way to pass arrays as bound parameters to queries or procedures from PHP. This would be especially useful if you're letting Oracle handle most of your data manipulating (as you should).   She includes an example of how she's like it to work. Sadly, it doesn't but there are some ways that a developer could get close. Here's her process:   No queries in loops, please! In the ideal world... Put all your DML in stored procedures. str2tbl The list_pkg package list_pkg in your procedure list_pkg in your PHP Leveraging list_pkg   The list_pkg is based around this article from AskTom.
40961
On the PHP-Coding-Practices.com blog, there's a tutorial posted from Tim Koschuetzki in his "Composing Methods" series looking at assigning temporary variables.   When you have the same temporary variable assigned to more than once, split it up into two, unless it is a loop variable. [...] Temporary variables have various uses. They can be used as counters in loops, as collecting variables building up a result or as simple containers containing the result of a long-winded expression for easy reference.   He offers suggestions of using temporary variables, including changing references of it after use and making a new temp variable following the second assignment of the first one. Some sample code is included to illustrate the points made.
632891
Popular posts from PHPDeveloper.org for the past week:Job Posting: WorldNetJobs.com Seeks Expert PHP Developer (Multiple Locations - FL/MD/NY)Stefan Reuter's Blog: Profiling PHP ApplicationsRich Zygler's Blog: People work with WS-* web services in PHP? Why?PHPBuilder.com: Securing Data Sent Via GET RequestsKore Nordmann's Blog: Comparision of PHP image librariesJim Wynia's Blog:  WebDAV, PHP and YouPadraic Brady's Blog: Namespaces (or Yet Another Pointless Opinion Piece)Christopher Jones' Blog: PHP 5.2.5 RPMs with OCI8 and PDO_OCI are availableZend Developer Zone: PHP Abstract Podcast Episode 29: PHP Women Podcast (Recorded Live)Evert Pot's Blog: PHP WebDAV Integration Library
700973
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.
698334
Popular posts from PHPDeveloper.org for the past week:The Bakery: Six New Articles/Tutorials PostedEvert Pot's Blog: PHP: Arrays vs. ObjectsDevArticles: Learning AJAXInternet Super Hero: PHP: mysqli_fetch_all()David Coallier's Blog: PHP Namespaces (Part 1: Basic usage & gotchas)I/O Reader: 15 Cool Things & 12 Things to Dislike About PHPProPHP Podcast: Newscast - August 16, 2007PHPBuilder.com: Dynamic XML with PHPSite News: Popular Posts for the Week of 08.17.2007PRADO Watch Blog: PRADO Watch: Interview With Timani Tunduwani - Why I Moved From CakePHP to PRADO
466648
Stefan Koopmanschap has pointed out an interesting article over on the CIO magazine website that has some in the PHP community a bit up in arms about comments it makes towards the language.   The article, "You Used PHP to Write WHAT?!", covers the basics of the language - its status in the web programming world, the functionality it offers and the database interfaces it includes. They also include a hit list of reasons PHP is popular and why it's a good choice for your project.   Then things get a little strange - they move from their PHP praise to three things that have more to do with unresearched "facts" than the reality of the language:   Security and PHP Working with PHP and the shell Scaling and PHP (in enterprise environments)   These incorrect assumptions have lead to many comments both from the PHP community and from users of other languages (like Java and ColdFusion) sharing thoughts on the contents of the article and the language in general. Check out the article's comments to see for yourself.
259126
In an "interesting" post to The Codist blog, there's one developer's look at PHP and his confession that he'll never quite understand the appeal of the language.   How PHP can be so popular is beyond me; the whole sense of encouraging all of your html, code, bindings, javascript, even sql (as in the below example) into a single file is a nightmare.   He Goes on to talk about his experience with JSP versus PHP and some perspectives on how PHP lacks features he's used to or how other developers he's talked to had similar issues.   One thing that concerns me (and apparently several others in the PHP community) is that he keeps talking about procedural PHP code that's an "all in one page" kind of setup. Well, of course this can get messy quickly - that's no way to code anything, much less PHP. Organization means more than just breaking code up into chunks on your page (though it's a very low-level start). Plus, the sample code he provides is a joke - a PHP developer with a few weeks of experience could push out something 10x better.
769015
Felix Geisendorfer shares, in this new post to the ThinkingPHP blog, some of his experiences with writing his code using test driven development.   So far I've had tons of fun trying to create php code using test driven development. It caused my code to become a lot more structured/consistent because writing the tests shows you interfaces problems right away. This is because the process of writing the test forces you to think a lot more about *how* you want to use some class / piece of code vs. your traditional "how can I get task x done"-thinking.   He also points out another benefit - it makes refactoring the code even easier (so there's more of a likelyhood that you'll use it again and again). He talks specifics about a library that he's been working on and the processes he's gone through to make things work with the testing versus his normal development cycle.