rfc:remove_php4_constructors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:remove_php4_constructors [2014/11/17 20:48] – levim | rfc:remove_php4_constructors [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2014-11-17 | * Date: 2014-11-17 | ||
* Author: Levi Morrison < | * Author: Levi Morrison < | ||
- | * Status: | + | |
+ | | ||
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | PHP 4 constructors are methods that have the same name as the class they are defined in. PHP 5 preserved the ability to use PHP 4 style constructors in some cases. The strangeness of when the constructor is and isn't used increases the mental model for programmers. | + | PHP 4 constructors are methods that have the same name as the class they are defined in. PHP 5 preserved the ability to use PHP 4 style constructors in some cases; the strangeness of when the constructor is and isn't used increases the mental model for programmers. |
<PHP> | <PHP> | ||
Line 49: | Line 50: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes changes for two PHP versions: | + | PHP 7 will emit '' |
- | - **PHP 5.7**: an '' | + | PHP 7 will also stop emitting |
- | - **PHP 7.0**: methods with the same name as the class they are defined will not be recognized as constructors in any context; they will be treated as normal methods. | + | |
- | Some code samples in the [[# | + | Refer to the [[# |
==== Backward Incompatible Changes ==== | ==== Backward Incompatible Changes ==== | ||
- | This RFC will break code that relies on PHP 4 constructors. The solution | + | Since an '' |
+ | |||
+ | In PHP 8 recognition for old constructors | ||
==== Examples ==== | ==== Examples ==== | ||
Line 63: | Line 65: | ||
class Filter { | class Filter { | ||
- | // PHP 5.X: filter is a constructor | + | // PHP 5: filter is a constructor |
- | // PHP 5.7: filter is a constructor and an E_DEPRECATED is raised | + | // PHP 7: filter is a constructor and E_DEPRECATED is raised |
- | // PHP 7.0: No errror is raised; | + | // PHP 8: filter is a normal method and is not a constructor; no E_DEPRECATED is raised |
function filter($a) {} | function filter($a) {} | ||
} | } | ||
Line 71: | Line 73: | ||
$filter = new ReflectionMethod(' | $filter = new ReflectionMethod(' | ||
- | // PHP 5.X: bool(true) | + | // PHP 5: bool(true) |
- | // PHP 7.0: bool(false) | + | // PHP 7: bool(true) |
+ | // PHP 8: bool(false) | ||
var_dump($filter-> | var_dump($filter-> | ||
</ | </ | ||
Line 79: | Line 82: | ||
// function filter is not used as constructor in PHP 5+ | // function filter is not used as constructor in PHP 5+ | ||
class Filter { | class Filter { | ||
- | // PHP 5.0-5.6: E_STRICT " | + | // PHP 5: E_STRICT " |
- | // PHP 5.7: E_DEPRECATED " | + | // PHP 7: No error is raised |
- | // PHP 7.0: No errror | + | // PHP 8: No error is raised |
function filter($a) {} | function filter($a) {} | ||
function __construct() {} | function __construct() {} | ||
Line 93: | Line 96: | ||
// PHP 5.0.0 - 5.2.13, 5.3.0 - 5.3.2: E_STRICT " | // PHP 5.0.0 - 5.2.13, 5.3.0 - 5.3.2: E_STRICT " | ||
- | // PHP 5.2.14 - 5.2.17, 5.3.3 - 5.6: No errror | + | // PHP 5.2.14 - 5.2.17, 5.3.3 - 5.6: No error is raised |
- | // PHP 5.7: No errror | + | // PHP 7: No error is raised |
- | // PHP 7.0: No errror | + | // PHP 8: No error is raised |
function filter($a) {} | function filter($a) {} | ||
} | } | ||
</ | </ | ||
- | ==== Impact to Opcache ==== | + | <PHP> |
- | Opcache | + | class Filter { |
+ | // PHP 5: filter is a constructor | ||
+ | // PHP 7: filter is a constructor and E_DEPRECATED is raised | ||
+ | // PHP 8: filter is a normal method and is not a constructor; | ||
+ | function filter() {} | ||
+ | } | ||
+ | |||
+ | class FilterX extends Filter { | ||
- | ===== Open Issues ===== | + | function __construct() { |
- | There are some tests that rely on behavior that this RFC would remove to trigger error conditions((See [[https://github.com/php/php-src/blob/f0c926564c5f7de9462d9ca7bd75014b14a63f56/ | + | |
+ | | ||
+ | | ||
+ | parent:: | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | new FilterX(); | ||
+ | </ | ||
===== Voting ===== | ===== Voting ===== | ||
- | This RFC targets PHP 7 and PHP 5.7: | + | This RFC targets PHP 7 and PHP 8. Please read the RFC to understand what is being proposed. |
- | PHP 5.7: Raise '' | + | This RFC requires 2/3 vote in favor of deprecating and removing |
- | PHP 7.0: Stop recognizing methods with the same name as the class they are defined in as constructors. | + | |
- | This RFC requires 2/3 vote in favor of removing | + | Do you vote to remove |
- | ===== Patches and Tests ===== | + | <doodle title=" |
- | A partial implementation based on the master branch can be found here: https:// | + | * Yes |
+ | * No | ||
+ | </doodle> | ||
- | The tests for this behavior have not yet been fixed. As mentioned in [[# | + | Voting will close on the evening (UTC-7) of March 6th. |
+ | |||
+ | ===== Patches and Tests ===== | ||
+ | An implementation based on the master branch can be found here: https:// | ||
- | ===== References ===== | ||
- | TODO: dig up pains caused by PHP 4 constructors in PHP 5 \\ | ||
- | Links to external references, discussions or RFCs |
rfc/remove_php4_constructors.1416257336.txt.gz · Last modified: 2017/09/22 13:28 (external edit)