|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: privat at ulrich-kapp dot de
New email:
PHP Version: OS:


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

    [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));



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-20 10:48 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: PHP Language Specification +Package: Scripting Engine problem
 [2020-01-20 10:48 UTC]
Function calls are not allowed in constant expressions; this
should be clarified in the manual.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Oct 04 04:05:53 2022 UTC