Take the State of PHP 2026 Survey →

Reclassify E_STRICT notices View as Markdown

Implemented (PHP 7.0)
Authors
Nikita Popov nikic@php.net
Date
2015-02-22
Source
wiki.php.net/rfc/reclassify_e_strict

Vote

Reclassify E_STRICT notices as described in this RFC? closed
Yes
28
No
4
32 voters
adobkin Yes 2015-03-17 06:52
aharvey Yes 2015-03-17 00:18
ajf Yes 2015-03-16 02:07
brandon Yes 2015-03-16 15:45
bwoebi Yes 2015-03-15 15:52
chx Yes 2015-03-16 14:04
damz Yes 2015-03-16 12:02
davey Yes 2015-03-21 05:32
eliw Yes 2015-03-17 22:28
frozenfire Yes 2015-03-16 18:01
jedibc Yes 2015-03-16 09:32
jwage Yes 2015-03-15 22:05
kguest No 2015-03-16 11:54
kinncj Yes 2015-03-23 16:25
laruence Yes 2015-03-16 12:59
lcobucci Yes 2015-03-16 15:38
levim Yes 2015-03-15 18:09
mbeccati No 2015-03-16 11:43
nikic Yes 2015-03-15 17:35
pajoye Yes 2015-03-19 00:29
patrickallaert Yes 2015-03-16 15:03
pauloelr Yes 2015-03-16 02:31
philstu Yes 2015-03-15 22:10
ramsey Yes 2015-03-23 21:53
rdohms Yes 2015-03-19 13:05
rmf Yes 2015-03-18 00:26
santiagolizardo No 2015-03-24 20:05
stas No 2015-03-15 22:18
stelianm Yes 2015-03-17 19:53
theseer Yes 2015-03-24 20:34
timo Yes 2015-03-16 15:13
yunosh Yes 2015-03-16 13:31

Discussions on the mailing list

Reclassify E_STRICT notices
by Nikita Popov · 16 messages
Mark some functions with PREFER_REF
by Nikita Popov · 3 messages
[VOTE] Reclassify E_STRICT notices
by Nikita Popov · 17 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

This RFC proposes to reclassify the few existing E_STRICT notices and remove this error category.

This is accomplished by doing one of the following:

  • Remove the strict standards notice if it appears inconsistent or informational.
  • Promote to E_DEPRECATED if there is intent to remove this functionality in the future.
  • Promote to E_NOTICE or E_WARNING otherwise.

The motivation behind this change is to simplify our error model and resolve the currently unclear role of strict standards notices.

Proposal

The following section lists all strict standards notices currently in use (with code sample and error message) as well as the proposed resolution and the reasoning behind it.

The E_STRICT constant will be retained for better compatibility, it will simply no longer have meaning in PHP 7.

Indexing by a resource

$file = fopen(__FILE__, 'r');
$array[$file] = true;
 
// Resource ID#3 used as offset, casting to integer (3)

Proposed resolution: Convert to E_NOTICE.

Reason: E_NOTICE is also used for array to string and object to int/float conversions.

Abstract static methods

abstract class Foo {
	abstract static function bar();
}
 
// Static function Foo::bar() should not be abstract

Proposed resolution: Remove notice.

Reason: We currently allow the use of abstract static functions in interfaces, as such it is inconsistent to not allow them as abstract methods. By using late static binding a method in the abstract class can reasonably depend on the existence of a static method in a superclass. (As far as any usage of LSB can be considered reasonable).

"Redefining" a constructor

Update: This notice is already removed by the deprecation of PHP 4 constructors - this section is no longer relevant, just keeping it here for the overview.

class Foo {
	function foo() {}
	function __construct() {}
}
 
// Redefining already defined constructor for class Foo

Proposed resolution: Remove notice.

Reason: If a PHP 5 constructor exists, the PHP 4 constructor will be a normal method, as such the notice is somewhat bogus. It is also order dependent, i.e. it will not be thrown if the order of foo and __construct is swapped.

Signature mismatch during inheritance

class Foo {
	public function method() {}
}
class Bar extends Foo {
	public function method($arg) {}
}
 
// Declaration of Bar::method() should be compatible with Foo::method()

Proposed resolution: Convert to E_WARNING.

Reason: If the same signature mismatch occurs when implementing an interface or an abstract function a fatal error is thrown instead of a strict standards notice. A signature mismatch is a significant issue, which will likely prevent the use of the child object in place of the parent object.

Same (compatible) property in two used traits

trait A {
	public $prop;
}
trait B {
	public $prop;
}
class C {
	use A, B;
}
 
// A and B define the same property ($prop) in the composition of C.
// This might be incompatible, to improve maintainability consider
// using accessor methods in traits instead.

Proposed resolution: Remove notice.

Reason: This appears to be a purely informational notice about coding style.

Accessing static property non-statically

class Foo {
	public static $prop = 24;
}
$obj = new Foo;
$obj->prop = 42;
 
// Accessing static property Foo::$prop as non static

Proposed resolution: Convert to E_NOTICE

Reason: E_NOTICE is used for a number of other property related noticed, like indirect modification or undefined properties. Accessing a static property non-statically makes it look like the property is only changed on the object, which is not true.

Only variables should be assigned by reference

$a =& substr("foo", 1);
 
// Only variables should be assigned by reference

Proposed resolution: Convert to E_NOTICE

Reason: E_NOTICE is used when you try to return the result of a by-value function call by-reference, which is a conceptually similar situation.

Only variables should be passed by reference

function by_ref(&$ref) {}
by_ref(substr("foo", 1));
 
// Only variables should be passed by reference

Proposed resolution: Convert to E_NOTICE

Reason: E_NOTICE is used when you try to return the result of a by-value function call by-reference, which is a conceptually similar situation.

Calling non-static methods statically

class Foo {
	public function method() {}
}
Foo::method();
 
// Non-static method Foo::method() should not be called statically

Proposed resolution: Convert to E_DEPRECATED

Reason: This is already deprecated if the call occurs from an instance method. Not annotating methods as static is an obsolete PHP4-ism.

Backward Incompatible Changes

Some of the strict standards notices are converted to an error category that is considered more severe. As such error handlers might treat it more severely, resulting in BC breakage.

The E_STRICT constant will be retained, as such existing error_reporting(E_ALL|E_STRICT) calls will continue to work fine.

Vote

Requires a 2/3 majority, as it is a language change. Voting started on 2015-03-15 and ended on 2015-03-25.

Vote: Reclassify E_STRICT notices as described in this RFC? — Yes: 28 · No: 4 (closed)

Patch

https://github.com/php/php-src/pull/1177