Bug->Doc #51340 [Opn]: const keyword inside code blocks causes parse error.
Edit report at http://bugs.php.net/bug.php?id=51340&edit=1
ID: 51340
Updated by: johannes@php.net
Reported by: wrzasq at gmail dot com
Summary: const keyword inside code blocks causes parse error.
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: Scripting Engine problem
Operating System: Debian GNU/Linux x86_64
PHP Version: 5.3.2
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-03-21 04:15:39] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51340&edit=1
Thread (2 messages)