Prepare for PHP 7 error messages In the article “Prepare for PHP 7 error messages (part 1)” from last week, we covered the evolution of error messages in the PHP binary. In order to prepare for prepare for PHP 7 error messages, we are now going to review the new messages that are appearing in […]
Prepare for PHP 7 error messages The first step to prepare for PHP 7 is to lint it : using the command line instruction ‘php -l script.php’, one can easily check that every file in a current application compile with PHP 7. The second step is to run the application and the unit tests : in […]
How code dies Code is born, grows, matures, decays and then dies. It may be seen as a living matter, just like the tulips in my garden. It is scary to transpose that image to code: little typo appearing, pieces of code disappearing, constants that changes their value over time (code inflation?), part of code […]
How many improvement can you spot in this one liner ? echo (“this “.$will.” be displayed.”); No need for parenthesis with echo The first, and probably the most obvious, are the useless parenthesis. The echo is a ‘structure of language’, aka a special kind of function for PHP : among others, it doesn’t need any […]
Magic number is a literal value with unexplained meaning, that appears in the code multiple times. Such values will show no intent, and should be replace by a constant: the name of the constant will make the code more readable, and easier to update in the future. Hunting for Magic Numbers Let’s take a look […]
Why to use automated PHP Code Analysis Tools ? Traditional PHP Code Review demands an army of developers. Doing go PHP Code Review demands scarce experts. Sustainable PHP Code review demands tools that each uses to help manage the code. With the increasingly important of technical debt, in PHP as elsewhere, we’ve seen the last two […]
What are interfaces ? Interfaces, in PHP as in all other OOP languages, specify what methods must be implemented in a class. Interfaces gives names and arguments counts, but no content : the actual code will be provided by the class. <?php interface movable { function move($distance) ; } class human implements movable { public function move($distance) […]
Static audit are a great tool to help with code quality. Audits means that the code being written is reviewed by an external auditor. Human auditors are usually the best, though they are not always available. Static auditing provides an automated way to review the code, and receive feedback on it. It checks every file […]
Caching with PHP static variables Whenever a methodcall is used repeatedly in a piece of code, you may wonder if it wouldn’t be more efficient to cache the value locally, avoid the functioncall altogether and speed up the process. Let us see how we can cache with PHP static variables. Functioncalls are rather intensive : PHP […]
Clear PHP reaches 100 rules Last week, we published the 100th rule in clear PHP. They represent recommendations to write clear PHP code. Such recommendations has various effect : avoid common pitfalls (No Unchecked Resources) prepare code for recent versions (Use Smart Autoload) complete some check that the engine doesn’t do ( No Switch With […]