====== PHP RFC: Constant Scalar Expressions (re-opening) ====== * Version: 1.0 * Date: 2013-10-18 (original's date was 2013-08-13) * Author: Andrea Faulds (copied from the withdrawn RFC by Anthony Ferrara ) * Status: Withdrawn due to improved proposal by bwoebi: [[rfc:const_scalar_exprs|PHP RFC: Constant Scalar Expressions]] * First Published at: http://wiki.php.net/rfc/const_scalar_expressions2 (copied from the RFC at https://wiki.php.net/rfc/const_scalar_expressions) ===== Introduction ===== Sadly, Anthony Ferrara decided to stop developing PHP and withdrew all of his RFCs. Since I liked this one, I am re-opening it here. The original RFC was at https://wiki.php.net/rfc/const_scalar_expressions2. I am enormously indebted to him for this, as he designed and implemented the entire thing, and I am merely responsible for trying to push it through the RFC process now that he has left. This RFC brings static scalar expressions to the parser. This allows places that only take static values (const declarations, property declarations, function arguments, etc) to also be able to take static expressions. This can allow for writing far easier to understand code, by allowing for far more expressive code. ===== Proposal ===== Adding parser support for compile-time resolved scalar expressions. ==== Supported Operations ==== The following operations are currently supported by this proposal: * //+// - Addition * //-// - Subtraction * //*// - Multiplication * ///// - Division * //%// - Modulus * //!// - Boolean Negation * //~// - Bitwise Negation * //|// - Bitwise OR * //&// - Bitwise AND * //^// - Bitwise XOR * //<>// - Bitwise Shift Right * //.// - Concat Also supported is grouping static operations: //(1 + 2) + 3//. ==== Supported Operands ==== * //123// - Integers * //123.456// - Floats * //"foo"// - Strings * //__LINE__// - Line magic constant * //__FILE__// - File magic constant * //__DIR__// - Directory magic constant * //__TRAIT__// - Trait magic constant * //__METHOD__// - Method magic constant * //__FUNCTION__// - Function magic constant * //__NAMESPACE__// - Namespace magic constant * //<<// - HEREDOC string syntax ==== Constant Declarations ==== Note that constants are not supported within a declaration (since this happens at compile time). So //const BIZ = FOO << BAR;// would be a compile error. ==== Class Constant Declarations ==== ==== Class Property Declarations ==== ==== Function Argument Declarations ==== ==== Static Variable Declarations ==== ===== Backward Incompatible Changes ===== None ===== Proposed PHP Version(s) ===== PHP 5.NEXT ===== SAPIs Impacted ===== None ===== Impact to Existing Extensions ===== None ===== Impact to Opcode Caching ===== None, as this is a pure compile-time construct, the generated op-array is the same as if there was no expression (it's purely static). ===== New Constants ===== None ===== php.ini Defaults ===== None ===== Vote ===== * Yes * No Opened 1st November 2013, ends 8th November 2013. The above vote was cancelled due to bwoebi's intervention with his patch to support constants within these expressions. ===== Patches and Tests ===== An implementation based off of current master is available: [[https://github.com/TazeTSchnitzel/php-src/tree/static_operation_parsing|Implementation On GitHub]] ([[https://github.com/TazeTSchnitzel/php-src/compare/static_operation_parsing|Diff On GitHub]]) This is, again, based off Anthony Ferrara's work: https://github.com/ircmaxell/php-src/tree/static_operation_parsing This patch is ready to be merged with tests.