php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67455 Allow dynamic expression for const
Submitted: 2014-06-16 17:15 UTC Modified: 2014-06-16 18:18 UTC
From: hacksmw at naver dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.6.0beta4 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-06-16 17:15 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-16 18:18 UTC] johannes@php.net
-Status: Open +Status: Wont fix
 [2014-06-16 18:18 UTC] johannes@php.net
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)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC