php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50068 const problem
Submitted: 2009-11-03 20:16 UTC Modified: 2009-11-04 13:48 UTC
From: jachym dot tousek at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.1RC3 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jachym dot tousek at gmail dot com
New email:
PHP Version: OS:

 

 [2009-11-03 20:16 UTC] jachym dot tousek at gmail dot com
Description:
------------
const is not working

Reproduce code:
---------------
<?php
const ROOT_DIR = __DIR__ . '/..'; //parse error


<?php
define('ROOT_DIR',__DIR__ . '/..'); //works fine



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-03 21:11 UTC] ksingla@php.net
I think this behavior is by design. const expressions are evaluated at compile time. So only few operations are supported in a const expression and string concatenation is not one of those. I could repro this in PHP 5.2 (after putting it under a class).
 [2009-11-03 21:46 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2009-11-03 22:26 UTC] jachym dot tousek at gmail dot com
Well i've checked [http://www.php.net/manual/en/language.constants.syntax.php] and also updated from 5.3.0 to 5.3.1RC3 before sending this report, but there is nothing about const name = 'value'; being different from define('name','value'); and i can not understand it even now.
 [2009-11-04 01:44 UTC] scottmac@php.net
const is a compile time constant and only allows simple scalar values.

define is a constant resolved at runtime and it allows full expressions when being defined.
 [2009-11-04 13:48 UTC] jachym dot tousek at gmail dot com
OK i get it now, but still it should be in documentation.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC