All I ever see of the PHP Strict Standards are errors reported when (ini_get('error_reporting') & E_STRICT) == true
. 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. Where can I find the PHP Strict Standards?
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
. Basically, look here at the master branch: 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.
Of course, understanding PHP's source would be difficult without an understanding of C and some of the common internals terminology.
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.
In PHP 5.5, calling any mysql_*
function would also produce an E_STRICT
, as of PHP 5.6 it produces an E_NOTICE
.
There are likely other places that emit them in PECL extensions, feel free to edit them in here if you find one.
class ClassName
{
public static $propName = 1;
}
$o = new ClassName;
echo $o->propName; // error here
$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
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
abstract class ClassName
{
abstract public static function methodName(); // error here
}
class OtherClassName extends ClassName
{
public static function methodName()
{
return 1;
}
}
// 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
{
}
}
// 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;
}
}
// Emitted when calling mktime() with no arguments
$time = mktime(); // error here
// 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
// 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. A common place that will list these is the Migration List that is put out when PHP minor versions (ie 5.X) are release. Here's the 5.4 backwards incompatability list , which shows what has E_STRICT
notices now. I think this is the best you can get.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.