php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62029 Allow expressions for const
Submitted: 2012-05-14 15:53 UTC Modified: 2014-08-30 07:57 UTC
Votes:4
Avg. Score:3.5 ± 1.7
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: zyss at mail dot zp dot ua Assigned: requinix (profile)
Status: Closed Package: *General Issues
PHP Version: 5.3.13 OS: All
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zyss at mail dot zp dot ua
New email:
PHP Version: OS:

 

 [2012-05-14 15:53 UTC] zyss at mail dot zp dot ua
Description:
------------
Currently PHP supports global constant definition using keyword const instead of ugly define() function call.

The problem is that const definition doesn't allow expressions to be used to define a constant.

So please implement the ability to use expressions when using const keyword.

Test script:
---------------
<?php
  const TIMEOUT = 10 * 60;

  const SITE_ROOT = __DIR__;
  const PAGES_DIR = '/pages/';
  const PAGES_ROOT = SITE_ROOT . PAGES_DIR;

Expected result:
----------------
All constants defined.

Actual result:
--------------
Parse error:  syntax error, unexpected '*', expecting ',' or ';' in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-30 07:57 UTC] requinix@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: requinix
 [2014-08-30 07:57 UTC] requinix@php.net
Added in 5.6.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 23:01:33 2025 UTC