rfc:dynamic_class_constant_fetch

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:dynamic_class_constant_fetch [2022/11/04 14:11] – created ilutovrfc:dynamic_class_constant_fetch [2023/02/02 17:17] (current) – Move to implemented ilutov
Line 3: Line 3:
   * Date: 2022-11-04   * Date: 2022-11-04
   * Author: Ilija Tovilo, tovilo.ilija@gmail.com   * Author: Ilija Tovilo, tovilo.ilija@gmail.com
-  * Status: Draft+  * Status: Implemented
   * Target Version: PHP 8.3   * Target Version: PHP 8.3
   * Implementation: https://github.com/php/php-src/pull/9793   * Implementation: https://github.com/php/php-src/pull/9793
Line 16: Line 16:
   - Methods <php>$foo->{$bar}()</php>   - Methods <php>$foo->{$bar}()</php>
   - Static methods <php>Foo::{$bar}()</php>   - Static methods <php>Foo::{$bar}()</php>
 +  - Classes for static properties <php>$foo::$bar</php>
   - Classes for static methods <php>$foo::bar()</php>   - Classes for static methods <php>$foo::bar()</php>
  
Line 52: Line 53:
 ==== {} expression type ==== ==== {} expression type ====
  
-The result of the expression in the braces <php>{}</php> must be of type <php>string</php>. If it is not, an +The result of the expression in the braces <php>{}</php> must be of type <php>string</php>. If it is not, a 
-<php>Error</php> is thrown.+<php>TypeError</php> is thrown.
  
 <code php> <code php>
 echo Foo::{[]}; echo Foo::{[]};
-// ErrorIllegal offset type+// TypeErrorCannot use value of type array as class constant name
 </code> </code>
  
Line 122: Line 123:
  
 // Can't be demonstrated because there is no __getStatic // Can't be demonstrated because there is no __getStatic
-// Foo::${test('foo')}::${test('bar')};+Foo::${test('foo')}::${test('bar')};
 // foo // foo
 // Static property foo // Static property foo
 // bar // bar
 // Static property bar // Static property bar
-</php>+</code>
  
-Property and array accesses evaluate all expressions in the chain before performing any of the actual operations. For +Property and array accesses evaluate all expressions in the chain before performing any of the actual operations. The reason for this is rather [[https://www.npopov.com/2017/04/14/PHP-7-Virtual-machine.html#writes-and-memory-safety|technical]]. Basically, no userland code must run between property or array accesses to avoid reallocation and thus potentially invalidating pointers. This problem does not apply to class constants. Thus, the simpler and more intuitive in-order approach is chosen. Evaluation order for class constants is also unlikely to matter since chaining them is of dubious usefulness.
-constants, order is less relevant because it's very rare for them to be chained. Thus, the simpler approach is chosen+
-which is evaluating them in order.+
  
 <code php> <code php>
-// Foo::{test('foo')}::{test('bar')};+Foo::{test('foo')}::{test('bar')};
 // foo // foo
 // Class constant foo // Class constant foo
Line 169: Line 168:
 ===== Vote ===== ===== Vote =====
  
-Voting starts ??? and ends ???+Voting starts 2022-12-22 and ends 2023-01-05
  
 As this is a language change, a 2/3 majority is required. As this is a language change, a 2/3 majority is required.
rfc/dynamic_class_constant_fetch.1667571070.txt.gz · Last modified: 2022/11/04 14:11 by ilutov