rfc:use_global_elements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:use_global_elements [2020/01/28 14:20] – formatting tandrerfc:use_global_elements [2020/02/11 19:05] (current) – Declined tandre
Line 1: Line 1:
  
 ====== PHP RFC: declare(function_and_const_lookup='global') ====== ====== PHP RFC: declare(function_and_const_lookup='global') ======
-  * Version: 0.9 + 
-  * Date: 2020-01-27+  * Version: 0.9.1 
 +  * Date: 2020-01-28
   * Author: Tyson Andre <tandre@php.net>   * Author: Tyson Andre <tandre@php.net>
-  * Status: Under Discussion+  * Status: Declined
   * First Published at: https://wiki.php.net/rfc/use_global_elements   * First Published at: https://wiki.php.net/rfc/use_global_elements
- 
  
 ===== Introduction ===== ===== Introduction =====
Line 28: Line 28:
       * Some builtins such as ''%%__DIR__%%'' and ''empty()'' aren't actually constants/functions, and they can't be prefixed by backslashes.       * Some builtins such as ''%%__DIR__%%'' and ''empty()'' aren't actually constants/functions, and they can't be prefixed by backslashes.
       * Version control history for lines would change if ''MY_CONST'' was replaced with ''\MY_CONST''       * Version control history for lines would change if ''MY_CONST'' was replaced with ''\MY_CONST''
-      * New contributors to a project would often be unfamiliar with any applicable coding style guideline of fully qualifying function/const uses.+      * New contributors to a project would often be unfamiliar with any applicable coding style guidelines of fully qualifying function/const uses.
   - Avoid using namespaces (this is forbidden by [[https://www.php-fig.org/psr/psr-1/#3-namespace-and-class-names|PSR-1]])   - Avoid using namespaces (this is forbidden by [[https://www.php-fig.org/psr/psr-1/#3-namespace-and-class-names|PSR-1]])
   - Mixes of the above approaches.   - Mixes of the above approaches.
Line 127: Line 127:
 8.0 8.0
  
-===== Proposed Voting Choices =====+===== Vote =====
  
-==== Yes/No Vote ====+Voting started 2020-01-28 and ends 2020-02-11.
  
-(Requires 2/3 vote to pass)+The overall change requires a 2/3 majority.
  
-=== Severity of redundant uses ===+<doodle title="Support declare(function_and_const_lookup=...)" auth="tandre" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
-When ''declare(function_and_const_lookup='global')'' and ''use <element_type> global_element_name;'' are both used in a namespace block, due to the latter being redundant when referring to the global namespace, php will do the following when the file is required: 
  
-  Warning (as described in the RFC) +Secondary vote: When ''declare(function_and_const_lookup='global')'' and ''use <element_type> global_element_name;'' are both used in a namespace block, due to the latter being redundant when referring to the global namespace, php will do the following when the file is required: 
-  - Fatal Error+ 
 +  Emit a warning (as described in the RFC) 
 +  - Trigger a fatal Error
   - Allow it and don't warn   - Allow it and don't warn
  
Line 145: Line 149:
 Otherwise, the option of "Warning" or "Fatal Error" with the most votes wins. Otherwise, the option of "Warning" or "Fatal Error" with the most votes wins.
  
- +<doodle title="Severity of redundant uses of global functions/constants" auth="tandre" voteType="single" closed="true"> 
-(Note that explicitly adding ''use <element_type> global_element_name;'' to a php file has the effect of preventing a function/const from being declared with the same name but a different namespace (the current namespace) at compile time. +   * Warning 
-don'expect that to be a common practice.)+   * Fatal Error 
 +   * Allow and don'warn 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 228: Line 234:
  
 <blockquote> <blockquote>
-One option that I haven'seem much discussion on is the opposite: Always+One option that I haven'seen much discussion on is the opposite: Always
 only look in the global namespace. Any unimported unqualified usages will only look in the global namespace. Any unimported unqualified usages will
 be treated as fully qualified names. This would match the proposed be treated as fully qualified names. This would match the proposed
Line 251: Line 257:
 From that perspective, changing the name resolution rules to always look for the global symbol if unimported would actually slightly reduce the number of necessary "use" statements. From that perspective, changing the name resolution rules to always look for the global symbol if unimported would actually slightly reduce the number of necessary "use" statements.
  
-> and changing that default would require changing a lot of third party code.+> It's fairly common for NS\SubNS\ClassName to mention other classes from NS\SubNS\OtherClassName right now, 
 +> (more commonly than use Exception, use Throwable, etc in some cases), 
 +> and [opting into that a single setting such as ''declare(global_lookup=1)''
 +would require changing a lot of third party code [to get unambiguous function and constant resolution easily].
 > A separate option such as `declare(lookup_classes=global)` would allow migrating to that, > A separate option such as `declare(lookup_classes=global)` would allow migrating to that,
 > but would confuse developers switching between codebases using different settings of lookup_classes, > but would confuse developers switching between codebases using different settings of lookup_classes,
Line 270: Line 279:
 Arguments for: Arguments for:
  
-  * Classes don't have the ambiguity functions and constants do, and already have autoloaders, so we should encourage use of classes instead.+  * Classes don't have the ambiguity functions and constants do, and already have autoloaders, so we should encourage the use of classes instead.
   * Can potentially support ''use function Ns\SomeClass::some_method;'', ''use const Ns\SomeClass::SOME_CLASS_CONST'' instead   * Can potentially support ''use function Ns\SomeClass::some_method;'', ''use const Ns\SomeClass::SOME_CLASS_CONST'' instead
  
Line 356: Line 365:
  
 [[https://externals.io/message/107953|[RFC] "use global functions/consts" statement]] [[https://externals.io/message/107953|[RFC] "use global functions/consts" statement]]
 +
 +[[https://externals.io/message/108306|[VOTE] declare(function_and_const_lookup='global')]]
  
rfc/use_global_elements.1580221227.txt.gz · Last modified: 2020/01/28 14:20 by tandre