php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79141 Problem defining an array-type constant from a text file
Submitted: 2020-01-20 09:48 UTC Modified: 2020-01-20 10:48 UTC
From: privat at ulrich-kapp dot de Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 7.4.1 OS: Linux, other
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-01-20 09:48 UTC] privat at ulrich-kapp dot de
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);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-20 10:48 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: PHP Language Specification +Package: Scripting Engine problem
 [2020-01-20 10:48 UTC] cmb@php.net
Function calls are not allowed in constant expressions; this
should be clarified in the manual.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Feb 27 15:01:28 2020 UTC