rfc:internal_constructor_behaviour
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:internal_constructor_behaviour [2015/03/01 14:44] – danack | rfc:internal_constructor_behaviour [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2015-03-01 | * Date: 2015-03-01 | ||
* Author: Dan Ackroyd, Danack@php.net | * Author: Dan Ackroyd, Danack@php.net | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 12: | Line 12: | ||
i) to make the behaviour of these classes behave more consistently with the behaviour that most people would expect them to have. | i) to make the behaviour of these classes behave more consistently with the behaviour that most people would expect them to have. | ||
- | ii) setting the coding standards | + | ii) setting the behaviour |
If other internal classes that are not listed in this RFC are found to have behaviour that is not consistent with the behaviour listed in this RFC they should be treated as bugs and fixed at the next appropriate release. | If other internal classes that are not listed in this RFC are found to have behaviour that is not consistent with the behaviour listed in this RFC they should be treated as bugs and fixed at the next appropriate release. | ||
Line 42: | Line 42: | ||
</ | </ | ||
- | This RFC proposes setting a standard that internal classes should either return a valid instance of the class or throw an exception. Also for the classes listed | + | This RFC proposes setting a standard that internal classes should either return a valid instance of the class or throw an exception. Also for the classes listed to be changed in PHP 7 so that they follow this behaviour. |
=== Factory methods === | === Factory methods === | ||
- | The classes IntlDateFormatter, | + | The classes IntlDateFormatter, |
- | PHP is a multi-paradigm programming language which support | + | PHP is a multi-paradigm programming language which supports |
< | < | ||
Line 81: | Line 81: | ||
</ | </ | ||
- | This RFC proposes that this behaviour should be changed so that the constructor should throw an exception if the class cannot be created in usuable | + | This RFC proposes that this behaviour should be changed so that the constructor should throw an exception if the class cannot be created in a usable |
The list of classes that show this behaviour is: | The list of classes that show this behaviour is: | ||
Line 108: | Line 108: | ||
Fatal errors should only be used for fatal errors. This RFC proposes that the constructor for PDORow should be changed to throw an appropriate exception rather than giving a fatal error. | Fatal errors should only be used for fatal errors. This RFC proposes that the constructor for PDORow should be changed to throw an appropriate exception rather than giving a fatal error. | ||
+ | |||
+ | |||
+ | |||
+ | |||
Line 151: | Line 155: | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | The standard of either returning a usuable | + | The standard of either returning a usable |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | If anyone feels strongly about splitting the vote into separate parts, please say so. | ||
+ | Some of the Intl extension code has always had the behaviour of giving an error notice, and also throwing an exception for the same error. This behaviour should be cleaned up for the release of PHP 7, so that either an error is given, or an exception, but never both. | ||
- | ===== Proposed Voting Choices ===== | ||
- | The vote requires 2/3 to pass. | + | ===== Patches |
- | + | ||
- | Should the standard paradigm for constructors for internal objects to be to either return a usable instance of a class on success, | + | |
These classes will be corrected by making the constructor throw an exception rather than return null if the construction of the object fails. | These classes will be corrected by making the constructor throw an exception rather than return null if the construction of the object fails. | ||
Line 175: | Line 176: | ||
- | These classes would be corrected by detecting the invalid data in the constructor and throwing an exception at object construction time, rather giving an error when the created instance is used. | + | These classes would be corrected by detecting the invalid data in the constructor and throwing an exception at object construction time, rather |
* UConverter | * UConverter | ||
* SplFixedArray | * SplFixedArray | ||
Line 186: | Line 187: | ||
* Phar | * Phar | ||
* PharData | * PharData | ||
- | * PharFileInfo | + | |
The class PDORow will be changed to give an exception if an attempt is made to instantiate it from userland. | The class PDORow will be changed to give an exception if an attempt is made to instantiate it from userland. | ||
+ | The changes have been made in this branch: https:// | ||
- | ===== Patches and Tests ===== | + | The list of exceptions used are: |
- | I hope to fix all of these in a branch before opening the vote, so that people can see the details of the changes. | + | |
+ | Exception - finfo | ||
+ | |||
+ | IntlException -UConverter, | ||
+ | |||
+ | InvalidArgumentException - SplFixedArray | ||
+ | |||
+ | PDOException - PDO, PDORow | ||
+ | |||
+ | PharException - Phar, PharData, PharFileInfo | ||
+ | |||
+ | ReflectionException - ReflectionExtension, | ||
+ | |||
+ | |||
+ | |||
+ | ===== Voting | ||
+ | |||
+ | |||
+ | Should the standard paradigm for constructors for internal objects be to return a usable instance | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
- | At the very least all of the exception to be used for each class will be determined, | + | Voting |
===== Implementation ===== | ===== Implementation ===== | ||
After the project is implemented, | After the project is implemented, | ||
- | - the version(s) it was merged to | + | - the version(s) it was merged to: 7.0 |
- | - a link to the git commit(s) | + | - a link to the git commit(s): http:// |
- | - a link to the PHP manual entry for the feature | + | - a link to the PHP manual entry for the feature: No new manual entry, the changes are conforming to standard practice. |
rfc/internal_constructor_behaviour.1425221099.txt.gz · Last modified: 2017/09/22 13:28 (external edit)