简体   繁体   English

在哪里可以找到PHP严格标准定义

[英]Where can I find the PHP Strict Standards Definitions

All I ever see of the PHP Strict Standards are errors reported when (ini_get('error_reporting') & E_STRICT) == true . (ini_get('error_reporting') & E_STRICT) == true时,我见过的所有PHP严格标准都是错误报告。 Correcting these errors in an error driven way seems to be not optimal. 以错误驱动的方式纠正这些错误似乎不是最佳方法。

So in order to write code that is perfectly compliant with the PHP Strict Standards out of the box I would like to read what is defined in them. 因此,为了开箱即用地编写完全符合PHP Strict标准的代码,我想阅读其中定义的内容。 Where can I find the PHP Strict Standards? 在哪里可以找到PHP Strict标准?

All the searching I have done only leads to instructions of how to fix some arbitrary error reported by the Strict Standards, but never the Strict Standards themselves. 我所做的所有搜索仅导致有关如何解决严格标准报告的任意错误的说明,而从不指导严格标准本身。 Can anyone please provide a link? 任何人都可以提供链接吗?

The only way to know where all possibilities for an E_STRICT to be emitted would be to grep the source looking for E_STRICT . 知道在何处发出E_STRICT所有可能性的唯一方法是grep寻找E_STRICT的源。 Basically, look here at the master branch: http://lxr.php.net/search?q=&defs=&refs=E_STRICT&path=Zend%2F&hist=&project=PHP_TRUNK . 基本上,请看这里的master分支: http : //lxr.php.net/search?q=&defs=&refs=E_STRICT&path=Zend%2F&hist=&project=PHP_TRUNK Note that in some cases master may differ from a particular version in what E_STRICT errors are raised and when. 请注意,在某些情况下,master可能与特定版本有所不同,出现什么E_STRICT错误以及何时引发。

Of course, understanding PHP's source would be difficult without an understanding of C and some of the common internals terminology. 当然,如果不了解C和一些常见的内部术语,很难理解PHP的源代码。

Below is a complete list of the possible E_STRICT error messages in PHP 5.6 and bundled extensions (derived from http://lxr.php.net/s?refs=E_STRICT&project=PHP_5_6 ), along with a brief code sample that will provoke them. 以下是PHP 5.6和捆绑的扩展名(源自http://lxr.php.net/s?refs=E_STRICT&project=PHP_5_6 )中可能的E_STRICT错误消息的完整列表,以及将引起这些错误的简短代码示例。

In PHP 5.5, calling any mysql_* function would also produce an E_STRICT , as of PHP 5.6 it produces an E_NOTICE . 在PHP 5.5中,调用任何mysql_*函数也会产生E_STRICT ,从PHP 5.6开始,它将产生E_NOTICE

There are likely other places that emit them in PECL extensions, feel free to edit them in here if you find one. PECL扩展中可能还有其他发出它们的地方,如果您发现它们,请随时在此处进行编辑。


Accessing static property ClassName::$propName as non static 将静态属性ClassName :: $ propName访问为非静态

class ClassName
{
    public static $propName = 1;
}
$o = new ClassName;
echo $o->propName; // error here

Resource ID#1 used as offset, casting to integer (1) 资源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

Non-static method ClassName::methodName() should not be called statically (may include additional text: assuming $this from compatible context OtherClassName) 非静态方法ClassName :: methodName()不应被静态调用(可以包含其他文本:假定来自兼容上下文OtherClassName的$ this)

class ClassName
{
    public function methodName()
    {
        return 1;
    }
}
echo ClassName::methodName(); // error here

Only variables should be assigned by reference 仅变量应通过引用分配

function func()
{
    return 1;
}
$var = &func(); // error here

Only variables should be passed by reference 仅变量应通过引用传递

function func(&$arg)
{
    $arg = 1;
}
function func2()
{
    return 0;
}
func(func2()); // error here

Static function ClassName::methodName() should not be abstract 静态函数ClassName :: methodName()不应为抽象

abstract class ClassName
{
    abstract public static function methodName(); // error here
}
class OtherClassName extends ClassName
{
    public static function methodName()
    {
        return 1;
    }
}

Redefining already defined constructor for class ClassName 重新定义类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
    {
    }
}

Declaration of ClassName::methodName() should be compatible with OtherClassName::methodName() 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;
    }
}

You should be using the time() function instead 您应该改用time()函数

// Emitted when calling mktime() with no arguments
$time = mktime(); // error here

Only basic entities substitution is supported for multi-byte encodings other than UTF-8; 对于UTF-8以外的多字节编码,仅支持基本实体替换。 functionality is equivalent to htmlspecialchars 功能等效于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

There is no next result set. 没有下一个结果集。 Please, call mysqli_stmt_more_results()/mysqli_stmt::more_results() to check whether to call this function/method 请调用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

There isn't one unified place that lists all of the strict errors but I wouldn't necessarily expect one either. 没有一个统一的地方列出所有严格的错误,但我也不一定会期望一个。 That list would be enormous . 这个清单将是巨大的

What you can do is look for E_STRICT notices. 您可以做的是查找E_STRICT通知。 A common place that will list these is the Migration List that is put out when PHP minor versions (ie 5.X) are release. 列出这些的一个常见地方是在发行PHP次要版本(即5.X)时发布的迁移列表。 Here's the 5.4 backwards incompatability list , which shows what has E_STRICT notices now. 这是5.4向后不兼容列表 ,该列表显示E_STRICT现在注意到的内容。 I think this is the best you can get. 我认为这是最好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM