php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51340 const keyword inside code blocks causes parse error.
Submitted: 2010-03-21 04:15 UTC Modified: 2010-03-24 16:33 UTC
From: wrzasq at gmail dot com Assigned: degeberg (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.2 OS: Debian GNU/Linux x86_64
Private report: No CVE-ID: None
 [2010-03-21 04:15 UTC] wrzasq at gmail dot com
Description:
------------
I tried to define constant using new const keyword structure in PHP 5.3.

This one worked fine:

--
$ cat test1.php
<?php

const FOO = 1;
echo FOO;
--

I checkd also this one:
$ cat test2.php

--
<?php

if(true) {
    define('FOO', 1);
}

echo FOO;
--

But this one crushes:

--
$ cat test3.php
<?php

if(true) {
    const FOO = 1;
}

echo FOO;
--

In fact im not using PHP 5.3.2, but PHP 5.3.1, but i don't have any place to test it against PHP 5.3.2 and I don't see fix for this issue on changelog fixes list.

Expected result:
----------------
1
1
1

Actual result:
--------------
1
1
Parse error: syntax error, unexpected T_CONST in /home/wrzasq/public_html/engine/chillout/projects/application/test3.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-21 11:21 UTC] johannes@php.net
-Type: Bug +Type: Documentation Problem
 [2010-03-21 11:21 UTC] johannes@php.net
Constants defined using "const" are set during compile-time of the script whereas define() is done at runtime. By this const can't be used in conditional blocks, functions, ...

This should be documented properly.
 [2010-03-22 06:18 UTC] kalle@php.net
-Package: Scripting Engine problem +Package: Documentation problem
 [2010-03-24 16:33 UTC] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=296726
Log: Fixed PHP bug #51340 (const keyword inside code blocks causes parse error)
 [2010-03-24 16:33 UTC] degeberg@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: degeberg
 [2010-03-24 16:33 UTC] degeberg@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun May 17 02:00:01 2026 UTC