rfc:remove_php4_constructors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:remove_php4_constructors [2014/11/17 20:40] – levim | rfc:remove_php4_constructors [2015/03/10 19:20] – Close voting. levim | ||
---|---|---|---|
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 28: | Line 29: | ||
<PHP> | <PHP> | ||
- | // Defining __construct | + | // Defining __construct |
class Filter { | class Filter { | ||
function __construct() {} | function __construct() {} | ||
Line 36: | Line 37: | ||
} | } | ||
- | //… but the other way raises an E_STRICT | + | //But defining filter first raises an E_STRICT |
class Filter { | class Filter { | ||
- | // A constructor… | + | // Not a constructor… |
function filter($a) {} | function filter($a) {} | ||
- | //…until this overrides it and raises E_STRICT | + | // This raises E_STRICT |
function __construct() {} | function __construct() {} | ||
} | } | ||
Line 50: | 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 64: | 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 | + | // PHP 7: filter is a constructor |
- | // 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 72: | 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 80: | 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 94: | 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) {} | ||
} | } | ||
</ | </ | ||
- | ===== Proposed | + | <PHP> |
- | This RFC targets | + | class Filter { |
+ | // PHP 5: filter is a constructor | ||
+ | // PHP 7: filter is a constructor | ||
+ | // PHP 8: filter is a normal method and is not a constructor; | ||
+ | function filter() {} | ||
+ | } | ||
+ | |||
+ | class FilterX extends Filter { | ||
- | PHP 5.7: Raise '' | + | function __construct() { |
- | PHP 7.0: Stop recognizing methods with the same name as the class they are defined in as constructors. | + | // PHP 5: Filter:: |
+ | // PHP 7: Filter:: | ||
+ | // | ||
+ | parent:: | ||
+ | } | ||
- | ===== RFC Impact ===== | + | } |
- | This RFC has no impact to SAPI's or extensions. | + | |
- | ==== To Opcache ==== | + | new FilterX(); |
- | Opcache is likely to be unaffected by this proposal, but this has not yet been verified. | + | </ |
- | ===== Open Issues | + | ===== Voting |
- | There are some tests that rely on behavior that this RFC would remove to trigger error conditions((See [[https:// | + | This RFC targets PHP 7 and PHP 8. Please read the RFC to understand what is being proposed. |
- | ===== Proposed Voting Choices ===== | + | This RFC requires 2/3 vote in favor of deprecating and removing PHP 4 style constructors to pass. |
- | This RFC requires 2/3 vote in favor of removing PHP 4 style constructors to pass. | + | |
- | ===== Patches and Tests ===== | + | Do you vote to remove PHP 4 constructors as outlined in this RFC? |
- | A partial implementation based on the master branch can be found here: https:// | + | |
- | The tests for this behavior have not yet been fixed. As mentioned in [[# | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | 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.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1