Bug #77100 [Com]: Inconsistent behavior between constants and magic constants
| From: | a at b dot c dot de | Date: | Sat, 03 Nov 2018 21:27:48 +0000 |
| Subject: | Bug #77100 [Com]: Inconsistent behavior between constants and magic constants | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217809@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77100&edit=1
ID: 77100
Comment by: a at b dot c dot de
Reported by: fabien dot villepinte at gmail dot com
Summary: Inconsistent behavior between constants and magic
constants
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
To continue that: Which means that when run time comes around the names are free to be redefined as
user constants. But the literal identifiers aren't in the code any more so the only way they
can be accessed is through the constant('') construct.
The compile-time evaluation of magic constants also means
define('__DIR__', 0);
is legal, but
const __DIR__ = 0;
is not, since the latter definition happens at compile time too.
Maybe a check (c|sh)ould be made that users aren't trying to define() magic constants
themselves? I'd suggest prepopulating the constants table with them only I don't know how
something like constant('__LINE__') could work.
Previous Comments:
------------------------------------------------------------------------
[2018-11-03 16:54:34] cmb@php.net
FWIW, the docs[1] say:
| All these "magical" constants are resolved at compile time,
| unlike regular constants, which are resolved at runtime.
[1] <http://php.net/manual/en/language.constants.predefined.php>
------------------------------------------------------------------------
[2018-11-03 16:12:34] fabien dot villepinte at gmail dot com
Description:
------------
The functions define(), defined() and constant() don't work the same way whether the name of
the constant given as an argument is the name of an already defined constant or the name of a magic
constant.
For instance :
define('PHP_EOL', 0); // returns false and emits a notice
define('__DIR__', 0); // returns true
__DIR__; // returns the path of the current directory
constant('__DIR__'); // returns the value of the user-defined constant, 0 in this case
There is nothing in the documentation mentioning this case, so I can't say if the current
behavior is correct or not.
Test script:
---------------
<?php
var_dump(defined('__LINE__'));
var_dump(define('__LINE__', 'test'));
var_dump(constant('__LINE__'));
var_dump(__LINE__);
Actual result:
--------------
bool(false)
bool(true)
string(4) "test"
int(5)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77100&edit=1