I'm actually interested in making sure our codebase is free of errors that would be warned against by PHP's builtin error checking, but I'd like to see exactly what E_STRICT enforces. By extension, what are PHP's "strict standards"? I looked but couldn't find a comprehensive list.
Some strict standards that I know offhand from experience:
- Warn against calling non-static methods statically
- Warn against incompatible subclass function signatures
- Warn against assigning a value by reference
All I know about E_STRICT is that it warns against code which might break forward compatibility, but I'm not sure what that means concretely.
Is there a good resource out there for information on this?
E_STRICT
and "strict standards" are the same thing. (And they're removed in PHP 7.)The documentation presently has no list of
E_STRICT
-specific warnings, but we can construct one reasonably easily by searching the PHP source.The list below (which I believe to be accurate as of PHP 5.6) was formed on a Unix system via the following methodology:
Cloning the PHP Git repo:
Checking out version 5.6.0:
Searching for all C files (ones with
.h
and.c
extensions) containingE_STRICT
:Manually looking through each of the (21) matched files to find code emitting
E_STRICT
warnings, attempting to deduce the circumstances in which the warning would be emitted (I'm not a C programmer, but it's not too hard to take a good guess at this stuff, especially with the human-readable error messages right there in the code to guide you) then testing them at the interactive PHP shell to make sure I was right.Given that the methodology described above is slightly crude and depends upon the assumption that
E_STRICT
can be found in the source code next to all places whereE_STRICT
warnings are emitted, it's possible I've missed some stuff - but this is hopefully at least close to being a comprehensive list.Things in PHP that cause E_STRICT warnings
Calling
mktime()
with no argumentsUsing a resource as an array index
Passing a multi-byte encoding other than UTF-8 to
htmlentities
Declaring an abstract static method
Declaring a class with both a
__construct
method and an old-style constructor function named after the classCalling
mysqli_next_result
ormysqli::next_result
on a Mysqli connection object that does not have a next result to prepareOverriding a method in a subclass to take a different number of arguments to the same method in its parent
Declaring, compatibly, the same property in a trait and a class that uses it. This one is actually nicely documented:
An example of the strict mode warning:
Calling a non-static method statically
Referring to a static property non-statically
Directly passing the result of a function call by reference.
Note that passing other non-variables by reference, like literals or constants, is a fatal error instead of an
E_STRICT