When testing the exakat static analysis engine, we need to run it on real code : even better, use the largest PHP code base available. Open Source projects are a real blessing there, since they come in different shapes and stripes. Some projects dates back from PHP 3 and evolved until now, some are directly […]
Heredoc PHP Heredoc PHP 语法是PHP里面写入一大块的文字的方式,不是传统的使用单引号,双引号字符串分隔符。他依赖于 <<< 和一个用来表示这个字符串的结束的标示符。 <?php $string = <<<STRING $x elephpants STRING ; ?> Heredoc 还有一个Nowdoc替代, 它是Heredo的“单引号版本”。 它实际上在标示符定义上就是用了单引号,并且不会替换它里面的变量值。 <?php $string = <<<‘STRING’ $x elephpants STRING ; ?> Nowdoc 很少被使用。在Heredoc/Nowdoc的使用中,仅仅只有3%使用Nowdoc的语法。这个可能是因为Nowdoc最近才被加到语言中(PHP 5.3),又或者是典型的担心未来可能会要使用字符串中的变量。
Heredoc PHP Heredoc PHP syntax is a way to write large bloc of text inside PHP, without the classic single quote, double quotes delimiters. It relies on <<< and a token that will also mark the end of the string. <?php $string = <<<STRING $x elephpants STRING ; ?> Heredoc has also the Nowdoc alternative, that […]
静态分析指在不执行代码的情况下审查代码。这样的代码审查可以是一个项目的一个阶段,或者当代码被转移给一个新的程序员(他也可能是6个月后的你自己)的时候自然发生。在两种情况下,目的都是通过阅读代码找到缺陷,理解它和找到不可能的情况。
Static analysis refers to the review of code without executing it. Such review may be done as a phase of a coding project, or naturally occurring when the code is handed to a new programmer (That new programmer may also be yourself, six months later). In both case, the goal is to spot defects by […]
代码是如何死亡的 代码出生,成长,成熟,衰老然后死亡。它可能被视作一个生命体,就像我的花园里的郁金香一样。把这样一个图景放到代码上有点可怕:小小的笔误出现了,一点点代码消失了,常量随着时间的推移改变着它们的值(代码也有通货膨胀吗?),一部分代码长出来了没有任何道理。这样一个样子,那么难怪代码会有一个寿终正寝的时候。
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 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 […]
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 […]