|  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
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 17:01:30 2024 UTC