[PHP-BUG] Bug #79141 [NEW]: Problem defining an array-type constant from a text file

[email protected] ("privat at ulrich-kapp dot de") Mon, 20 Jan 2020 09:48:23 +0000
Newsgroups php.standards
Message-ID <[email protected]>
From:             privat at ulrich-kapp dot de
Operating system: Linux, other
PHP version:      7.4.1
Package:          PHP Language Specification
Bug Type:         Bug
Bug description:Problem defining an array-type constant from a text file

Description:
------------
When defining a constant of type array from a text file, the (shorter
and case sensitive) const command doesn't work, it throws a "Fatal
error: Constant expression contains invalid operations in php shell code
on line XY" error.

The following test script is performed in the command line (php -a)

The first command throws:
Fatal error: Constant expression contains invalid operations in php
shell code on line 1

The second works fine and the third gives the following result:

Array
(
    [0] => Line 1
    [1] => Line 2
    [2] => Line 3
    [3] => ...
)


Test script:
---------------
const myArrayConst = file("mytextfile.txt", FILE_IGNORE_NEW_LINES);

define ("myArrayConst", file("mytextfile.txt", FILE_IGNORE_NEW_LINES));

print_r(myArrayConst);


-- 
Edit bug report at https://bugs.php.net/bug.php?id=79141&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79141&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79141&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79141&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79141&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79141&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79141&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79141&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79141&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79141&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79141&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79141&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79141&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79141&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79141&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79141&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79141&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79141&r=mysqlcfg