我所见过的所有PHP严格标准都是在报告错误时报告的(ini_get('error_reporting') & E_STRICT) == true.以错误驱动的方式纠正这些错误似乎不是最佳的.
因此,为了编写完全符合PHP严格标准的代码,我想阅读其中定义的内容.我在哪里可以找到PHP严格标准?
我所做的所有搜索只会导致如何修复严格标准报告的任意错误的指示,但绝不会导致严格标准本身.有人可以提供链接吗?
知道E_STRICT发射所有可能性的唯一方法是grep寻找源E_STRICT.基本上,请查看主分支:http://lxr.php.net/search?q =&defs =&refs = E_STRICT&path = Zend%2F &hist =&project = PHP_TRUNK.请注意,在某些情况下,master可能与特定版本的不同之处在于E_STRICT引发的错误和时间.
当然,如果不了解C和一些常见的内部术语,理解PHP的来源将是困难的.
下面是E_STRICTPHP 5.6中可能的错误消息和捆绑扩展(源自http://lxr.php.net/s?refs=E_STRICT&project=PHP_5_6)的完整列表,以及将激发它们的简短代码示例.
在PHP 5.5中,调用任何mysql_*函数也会产生一个E_STRICT,从PHP 5.6开始它会产生一个E_NOTICE.
可能有其他地方在PECL扩展中发出它们,如果你找到它们,可以在这里编辑它们.
class ClassName
{
public static $propName = 1;
}
$o = new ClassName;
echo $o->propName; // error here
Run Code Online (Sandbox Code Playgroud)
$fp = fopen('file.txt', 'r');
$array[$fp] = 'something'; // error here
// it's worth noting that an explicit cast to int has the same effect with no error:
$array[(int)$fp] = 'something'; //works
Run Code Online (Sandbox Code Playgroud)
class ClassName
{
public function methodName()
{
return 1;
}
}
echo ClassName::methodName(); // error here
Run Code Online (Sandbox Code Playgroud)
function func()
{
return 1;
}
$var = &func(); // error here
Run Code Online (Sandbox Code Playgroud)
function func(&$arg)
{
$arg = 1;
}
function func2()
{
return 0;
}
func(func2()); // error here
Run Code Online (Sandbox Code Playgroud)
abstract class ClassName
{
abstract public static function methodName(); // error here
}
class OtherClassName extends ClassName
{
public static function methodName()
{
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
// Emitted when both a PHP4-style and PHP5-style constructor are declared in a class
class ClassName
{
public function ClassName($arg)
{
}
public function __construct($arg) // error here
{
}
}
Run Code Online (Sandbox Code Playgroud)
// Emitted when a class declaration violates the Liskov Substitution Principle
// http://en.wikipedia.org/wiki/Liskov_substitution_principle
class OtherClassName
{
public function methodName()
{
return 1;
}
}
class ClassName extends OtherClassName
{
public function methodName($arg) // error here
{
return $arg + 1;
}
}
Run Code Online (Sandbox Code Playgroud)
// Emitted when calling mktime() with no arguments
$time = mktime(); // error here
Run Code Online (Sandbox Code Playgroud)
// Emitted when using a multi-byte character set that is not UTF-8 with
// htmlentities and some related functions
echo htmlentities("<Stuff>", ENT_COMPAT | ENT_HTML401, '936'); // error here
Run Code Online (Sandbox Code Playgroud)
// Emitted by mysqli_next_result() when there are no more results
do {
// stuff
} while (mysqli_next_result($link)); // error here
Run Code Online (Sandbox Code Playgroud)