rfc:const_scalar_exprs

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:const_scalar_exprs [2013/11/03 00:45] – [Supported Operations] missed the not-variants bwoebirfc:const_scalar_exprs [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHP RFC: Constant Scalar Expressions ====== ====== PHP RFC: Constant Scalar Expressions ======
-  * Version: 0.1 
   * Date: 2013-11-03   * Date: 2013-11-03
   * Author: Bob Weinand <bwoebi@php.net>   * Author: Bob Weinand <bwoebi@php.net>
-  * Status: In Draft+  * Status: Implemented in PHP 5.6
   * First Published at: https://wiki.php.net/rfc/const_scalar_exprs   * First Published at: https://wiki.php.net/rfc/const_scalar_exprs
     * This is a follow-up to https://wiki.php.net/rfc/const_scalar_expressions from Anthony Ferrara <ircmaxell@php.net> (which was without constant support)     * This is a follow-up to https://wiki.php.net/rfc/const_scalar_expressions from Anthony Ferrara <ircmaxell@php.net> (which was without constant support)
Line 13: Line 12:
 This can allow for writing far easier to understand code, by allowing for far more expressive code.  This can allow for writing far easier to understand code, by allowing for far more expressive code. 
  
 +The main difference to Anthony's RFC is (apart from a few operators more) that constants can be involved in these scalar operations:
 +
 +<file php const_scalar_exprs_diff.php>
 +<?php
 +
 +const a = 1;
 +
 +const b = a?2:100; // here the value of the constant "b" is dependent on the constant "a"
 +
 +?>
 +</file>
 ===== Proposal ===== ===== Proposal =====
  
Line 31: Line 41:
   * //&// - Bitwise AND   * //&// - Bitwise AND
   * //^// - Bitwise XOR   * //^// - Bitwise XOR
-  * //<<// - Bitwise Shift Left +  * //<nowiki><<</nowiki>// - Bitwise Shift Left 
-  * //>>// - Bitwise Shift Right+  * //<nowiki>>></nowiki>// - Bitwise Shift Right
   * //.// - Concatenation   * //.// - Concatenation
   * //?:// - Ternary Operator   * //?:// - Ternary Operator
Line 61: Line 71:
   * //<nowiki>__FUNCTION__</nowiki>// - Function magic constant   * //<nowiki>__FUNCTION__</nowiki>// - Function magic constant
   * //<nowiki>__NAMESPACE__</nowiki>// - Namespace magic constant   * //<nowiki>__NAMESPACE__</nowiki>// - Namespace magic constant
-  * //<nowiki><<<HEREDOC</nowiki>// - HEREDOC string syntax+  * //<nowiki><<<HEREDOC</nowiki>// - HEREDOC string syntax (without variables) 
 +  * //<nowiki><<<'NOWDOC'</nowiki>// - NOWDOC string syntax
   * //SOME_RANDOM_CONSTANT// - Constants   * //SOME_RANDOM_CONSTANT// - Constants
   * //class_name::SOME_CONST// - Class constants   * //class_name::SOME_CONST// - Class constants
Line 129: Line 140:
     static $a = 1 + 1;     static $a = 1 + 1;
     static $b = [1 << 2];     static $b = [1 << 2];
-    static $c = 0x01 BAR;+    static $c = 0x01 BAR;
 } }
 ?> ?>
Line 145: Line 156:
  
 An implementation based off of current master is available: [[https://github.com/bwoebi/php-src/tree/const_scalar_exprs|Implementation On GitHub]] ([[https://github.com/bwoebi/php-src/compare/const_scalar_exprs|Diff On GitHub]]) An implementation based off of current master is available: [[https://github.com/bwoebi/php-src/tree/const_scalar_exprs|Implementation On GitHub]] ([[https://github.com/bwoebi/php-src/compare/const_scalar_exprs|Diff On GitHub]])
 +
 +The patch is ready to be merged. (Opcache support is included, thanks to Dmitry)
 +
 +===== Note on implementation =====
 +
 +The implementation of the scalar expressions is based on an AST. That AST implementation eventually could be used later as a general-purpose AST for compiler with a few tweaks.
 +
 +===== Vote =====
 +
 +<doodle title="Should the patch for this RFC be merged into PHP 5.6?" auth="bwoebi" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 +
 +The vote started the 20th November 2013 and ended the 27th November 2013.
rfc/const_scalar_exprs.1383439508.txt.gz · Last modified: 2017/09/22 13:28 (external edit)