rfc:engine_warnings
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:engine_warnings [2019/08/28 15:24] – Fix a few typos theodorejb | rfc:engine_warnings [2020/08/03 12:41] (current) – nikic | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2019-08-27 | * Date: 2019-08-27 | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.0 | * Target Version: PHP 8.0 | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | While newly introduced error conditions in the engine typically use '' | + | While newly introduced error conditions in the engine typically use '' |
===== Proposal ===== | ===== Proposal ===== | ||
Line 19: | Line 19: | ||
* If the error condition is data-dependent, | * If the error condition is data-dependent, | ||
* For error conditions that have known false positives, a notice should be used. | * For error conditions that have known false positives, a notice should be used. | ||
- | * Avoid promoting from notice directly to Error exception. I'm only doing this in one case (undefined variables), because it is mind-bogglingly | + | * Avoid promoting from notice directly to Error exception. I'm only proposing |
==== Proposed Classification ==== | ==== Proposed Classification ==== | ||
Line 26: | Line 26: | ||
The table shows both the current error level, as well as the proposed level. A rationale for the proposed change (or non-change) is provided below each group of errors. | The table shows both the current error level, as well as the proposed level. A rationale for the proposed change (or non-change) is provided below each group of errors. | ||
+ | |||
+ | The " | ||
^ Message ^ Current Level ^ Proposed Level ^ | ^ Message ^ Current Level ^ Proposed Level ^ | ||
- | | Undefined variable: %s | Notice | Error exception | | ||
- | | **Rationale: | ||
| Attempt to increment/ | | Attempt to increment/ | ||
| Attempt to modify property ' | | Attempt to modify property ' | ||
Line 63: | Line 63: | ||
| Array to string conversion | Notice | Warning | | | Array to string conversion | Notice | Warning | | ||
| **Rationale: | | **Rationale: | ||
- | | Undefined offset: %d | Notice | Warning | | ||
- | | Undefined index: %s | Notice | Warning | | ||
- | | **Rationale: | ||
| Resource ID#%d used as offset, casting to integer (%d) | Notice | Warning | | | Resource ID#%d used as offset, casting to integer (%d) | Notice | Warning | | ||
| **Rationale: | | **Rationale: | ||
Line 76: | Line 73: | ||
| Cannot assign an empty string to a string offset | Warning | Error exception | | | Cannot assign an empty string to a string offset | Warning | Error exception | | ||
| **Rationale: | | **Rationale: | ||
- | | Only variables should be passed by reference | Notice | ??? | | + | | Only variables should be passed by reference | Notice | (Notice) |
- | | Only variable references should be returned by reference | Notice | ??? | | + | | Only variable references should be returned by reference | Notice | (Notice) |
- | | Only variable references should be yielded by reference | Notice | ??? | | + | | Only variable references should be yielded by reference | Notice | (Notice) |
- | | Only variables should be assigned by reference | Notice | ??? | | + | | Only variables should be assigned by reference | Notice | (Notice) |
- | | Attempting to set reference to non referenceable value | Notice | ??? | | + | | Attempting to set reference to non referenceable value | Notice | (Notice) |
- | | Cannot pass by-reference argument %d of %s%s%s() by unpacking a Traversable, | + | | Cannot pass by-reference argument %d of %s%s%s() by unpacking a Traversable, |
- | | **Rationale: | + | | **Rationale: |
+ | |||
+ | ==== Undefined variable ==== | ||
+ | |||
+ | In most cases, accessing an undefined variable is a severe programming error. The current low classification is a legacy from the Dark Ages of PHP, where features like register_globals made conditionally defined variables more typical, and code quality standards were lower. | ||
+ | |||
+ | Ideally, undefined variables should be compile errors, but as the dynamic nature of PHP precludes a reliable compile-time analysis, this RFC proposes to generate an Error exception instead. | ||
+ | |||
+ | However, throwing an exception may complicate the upgrading of legacy code that currently suppresses the generation of notices wholesale, as the issue can no longer be ignored. Some people have even suggested that the use of undefined variables is a legitimate coding style choice. | ||
+ | |||
+ | For this reason, a separate vote will decide whether we should throw an Error exception, generate a warning or keep the current notice. | ||
+ | |||
+ | ==== Undefined array index ==== | ||
+ | |||
+ | Similarly to undefined variables or an undefined object properties, reading an undefined array index/key would generally be considered a programming error in modern PHP code. However, while variables and object properties are predominantly statically known (i.e., when variable variables and dynamic object properties are not used), the same is not true to array keys, which tend to be dynamic. | ||
+ | |||
+ | Some languages, such as JavaScript, do not consider accesses to undefined array keys to be an error condition at all, and allow such an operation to be performed silently. While it is not predominant in the PHP world, some people subscribe to such a coding style also for PHP code, and as such would prefer undefined array key access to remain an easily suppressible notice. | ||
+ | |||
+ | A separate vote will decide whether to elevate undefined array offset/ | ||
==== Division by zero ==== | ==== Division by zero ==== | ||
Line 98: | Line 113: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Conversion of noticed | + | Conversion of notices |
This may impact code that makes very liberal use of the error suppression operator '' | This may impact code that makes very liberal use of the error suppression operator '' | ||
+ | |||
+ | If desired, an error handler can be provided that filters out the error conditions that will be turned into an exception, so that projects can focus on addressing them prior to an upgrade. | ||
===== Vote ===== | ===== Vote ===== | ||
- | The main portion of this RFC will be voted as a single proposal. However, I may split off specific warnings into separate | + | All the following votes are **independent**. Each requires a 2/3 majority and may pass/fail independent of other votes. Voting closes 2019-09-26. |
+ | |||
+ | As the " | ||
+ | |||
+ | <doodle title=" | ||
+ | * Error exception | ||
+ | * Warning | ||
+ | * Keep Notice | ||
+ | </ | ||
+ | . | ||
+ | <doodle title=" | ||
+ | * Warning | ||
+ | * Keep Notice | ||
+ | </ | ||
+ | . | ||
+ | <doodle title=" | ||
+ | * DivisionByZeroError exception | ||
+ | * Keep Warning | ||
+ | </ | ||
+ | . | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | * 2019-09-12: Split out undefined index/ | ||
+ | * 2019-09-10: Keep current classification for reference errors. | ||
+ | * 2019-08-28: Split off the " |
rfc/engine_warnings.1567005894.txt.gz · Last modified: 2019/08/28 15:24 by theodorejb