rfc:namespace_scoped_declares
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:namespace_scoped_declares [2017/12/11 12:54] – nikic | rfc:namespace_scoped_declares [2022/01/25 18:22] (current) – Move to inactive ilutov | ||
---|---|---|---|
Line 4: | Line 4: | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
* Proposed PHP version: PHP 7.3 | * Proposed PHP version: PHP 7.3 | ||
- | * Status: | + | * Status: |
* PR: https:// | * PR: https:// | ||
* ML thread: http:// | * ML thread: http:// | ||
Line 124: | Line 124: | ||
This restriction is introduced for two reasons: Firstly, lack of such a restriction would imply that language behavior can silently change in the middle of a single file, which would be very confusing. Secondly, there are are significant implementational complexities associated with allowing this type of code due to limitations of specific declare directives. In particular the current implementation of '' | This restriction is introduced for two reasons: Firstly, lack of such a restriction would imply that language behavior can silently change in the middle of a single file, which would be very confusing. Secondly, there are are significant implementational complexities associated with allowing this type of code due to limitations of specific declare directives. In particular the current implementation of '' | ||
+ | |||
+ | ==== Supported declare directives ==== | ||
+ | |||
+ | Currently PHP supports three declare directives, '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | For '' | ||
+ | |||
+ | For '' | ||
==== Open Question: Handling of unknown directives ==== | ==== Open Question: Handling of unknown directives ==== | ||
Line 130: | Line 140: | ||
If we go for throwing a warning here, it might be beneficial to add a '' | If we go for throwing a warning here, it might be beneficial to add a '' | ||
+ | |||
+ | ==== Open Question: Introspection functionality ==== | ||
+ | |||
+ | It might be useful to also provide a mechanism to retrieve the active namespace-scoped declares at runtime, e.g. using a '' | ||
==== Implementation considerations ==== | ==== Implementation considerations ==== | ||
Declare directives have to be known at compile-time, | Declare directives have to be known at compile-time, | ||
- | |||
===== Disadvantages ===== | ===== Disadvantages ===== | ||
Line 145: | Line 158: | ||
Additionally it should be noted that the same problem (to an even worse degree) exists for the ini system, where ini options can be specified from many different sources (including multiple ini files, htaccess files and inline in PHP code). In practice this does not appear to be a major problem. | Additionally it should be noted that the same problem (to an even worse degree) exists for the ini system, where ini options can be specified from many different sources (including multiple ini files, htaccess files and inline in PHP code). In practice this does not appear to be a major problem. | ||
+ | |||
+ | Finally, while namespace-scoped declares may be less explicit, they fit better into the mental model we use as programmers. Libraries generally do not haphazardly switch between different strict_types files and instead use a consistent mode for the entire project. Namespace-scoped declares codify this and prevent mistakes like forgetting to add a declare directive when creating a new file. | ||
==== Proliferation of declare directives ==== | ==== Proliferation of declare directives ==== | ||
Line 157: | Line 172: | ||
Nonetheless, | Nonetheless, | ||
+ | |||
+ | ==== Discussion: Potential for abuse ==== | ||
+ | |||
+ | One issue that came up repeatedly during the first discussion, is that people perceived a potential for abuse in this feature. The concern is that it would be possible to call '' | ||
+ | |||
+ | I honestly do not understand this concern. PHP is already oversaturated with ways in which you could break external library code if one wants to (such as hijacking autoloading). If breaking library code is your goal, you don't need this feature to achieve that. However, the question remains why anyone would want to this, as in the end you only sabotage yourself. | ||
===== Alternatives ===== | ===== Alternatives ===== | ||
Line 180: | Line 201: | ||
* Resolve open question " | * Resolve open question " | ||
- | * Consider adding some introspection | + | * Resolve open question " |
- | * Investigate whether this mechanism can support the '' | + |
rfc/namespace_scoped_declares.1512996896.txt.gz · Last modified: 2017/12/11 12:54 by nikic