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
Votes:2
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: privat at ulrich-kapp dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC