下面是 PHP 5.6 中可能出现的 E_STRICT 错误消息和捆绑扩展(源自 http://lxr.php.net/s?refs=E_STRICT&project=PHP_5_6)的完整列表,以及会引发这些错误的简短代码示例。
在 PHP 5.5 中,调用任何 mysql_* 函数也会产生一个 E_STRICT,从 PHP 5.6 开始它会产生一个 E_NOTICE。
可能还有其他地方在 PECL 扩展中发出它们,如果你找到了,请随时在此处编辑它们。
以非静态方式访问静态属性 ClassName::$propName
class ClassName
{
public static $propName = 1;
}
$o = new ClassName;
echo $o->propName; // error here
资源 ID#1 用作偏移量,转换为整数 (1)
$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
不应静态调用非静态方法 ClassName::methodName()(可能包含附加文本:假设 $this 来自兼容上下文 OtherClassName)
class ClassName
{
public function methodName()
{
return 1;
}
}
echo ClassName::methodName(); // error here
只能通过引用分配变量
function func()
{
return 1;
}
$var = &func(); // error here
只能通过引用传递变量
function func(&$arg)
{
$arg = 1;
}
function func2()
{
return 0;
}
func(func2()); // error here
静态函数 ClassName::methodName() 不应该是抽象的
abstract class ClassName
{
abstract public static function methodName(); // error here
}
class OtherClassName extends ClassName
{
public static function methodName()
{
return 1;
}
}
为类 ClassName 重新定义已定义的构造函数
// 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
{
}
}
ClassName::methodName() 的声明应该与 OtherClassName::methodName() 兼容
// 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;
}
}
您应该改用 time() 函数
// Emitted when calling mktime() with no arguments
$time = mktime(); // error here
对于 UTF-8 以外的多字节编码,仅支持基本实体替换;功能等同于 htmlspecialchars
// 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
没有下一个结果集。请调用 mysqli_stmt_more_results()/mysqli_stmt::more_results() 检查是否调用此函数/方法
// Emitted by mysqli_next_result() when there are no more results
do {
// stuff
} while (mysqli_next_result($link)); // error here