Req #67455 [Opn->Wfx]: Allow dynamic expression for const
| From: | johannes@php.net | Date: | Mon, 16 Jun 2014 18:18:54 +0000 |
| Subject: | Req #67455 [Opn->Wfx]: Allow dynamic expression for const | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186214@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67455&edit=1
ID: 67455
Updated by: johannes@php.net
Reported by: hacksmw at naver dot com
Summary: Allow dynamic expression for const
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
PHP Version: 5.6.0beta4
Block user comment: N
Private report: N
New Comment:
This won't be added as it is hard to tell the user when exactly this will be evaluated (during
compilation phase? Then this might require not yet compiled things or trigger an autoloader; after
compilation of the file? - might miss thins from other files not executed, yet; when execution
passes the statement? - might be a wild jump,hard to debug; on first use? - Even more confusing)
Previous Comments:
------------------------------------------------------------------------
[2014-06-16 17:15:28] hacksmw at naver dot com
Description:
------------
In PHP 5.6, const supports static expression.
But it still does not support dynamic expression.
So please implement the ability to use dynamic expressions when using const.
I think that const should replace define() entirely.
const is much more readable and natural than define().
Test script:
---------------
<?php
const PI = atan(1)*4;
const RANDOM = rand();
echo PI . "\n";
echo RANDOM . "\n";
Expected result:
----------------
3.141592653589793
445
Actual result:
--------------
Parse error: syntax error, unexpected '(', expecting ',' or ';' in
C:\Users\hack
s_000\Desktop\test.php on line 2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67455&edit=1