静态审计是一个帮助提高代码质量的非常好的工具。审计意味着写下的代码被一个外部的审计师审查。人工的审计者通常是最好的,虽然他们不是总是适用。静态审计提供一个代码审查的自动的方法,并能很快地接收到反馈。它系统性地检查每一个文件的每一行代码。它不针对同人工审核一样的违规实例,但是也带来一系列的很好地优势:
什么是接口? 接口,在PHP中也像在其他的面向对象(OOP)的语言中一样,定义在一个类中有哪些方法必须实现。接口给名字和参数以记录,但是没有内容:实际的(实现)代码将会要类来提供。 <?php interface movable { function move($distance) ; } class human implements movable { public function move($distance) { $this->walk($distance); } } class dog implements movable { public function move($distance) { $this->run($distance); // dogs never walk… } } class marsrover implements movable { public function move($distance) { for($i = 0; $i < $distance / […]
When come the time for preparing a new server, there is always the dreaded question of configuration. Which directives have to be configured in php.ini. Certainly, we have (and love) the phpinfo() function, that displays the current configuration of a server. It is so useful to check that one directive has the good value or […]
神奇数字式一个没有解释其意义的字面值,而且它出现在代码里多次。这样的值将会显示没有任何意图,它应该被替换为常量:常量的名字将会使代码更可读,在未来更加容易更新。 ç 让我们来看看一些代码,并且把它的神奇数字分离出来来试图理解它的情况。这是一个真实的数字的例子,来源于最近发布的一个关于120 kLOC的开源应用。 Value Number of occurrences 0.0 1 1.0E-08 1 0.05 1 0.33 1 1.0 10 1.7 4 2.0 1 2.3 1 3.2 1 4.0 1 4.199999 1 4.299999 1 5.0 1 5.2 2 7.3 1 8.0 1 365.25 3 3600.0 1 用眼快速地扫一下显示: 0.33 看上去像是 1/3, 有点取一个近似值。它可以被取代为用被除数3的除法。 365.25 看上去像一个一年的时间用天表示。另外一个可疑的地方时整数365和366在应用中使用了多次。 几个整数被表达为实数(0, […]