Bug->Doc #79141 [Opn->Ver]: Problem defining an array-type constant from a text file

From: Date: Mon, 20 Jan 2020 10:48:41 +0000
Subject: Bug->Doc #79141 [Opn->Ver]: Problem defining an array-type constant from a text file
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17209@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79141&edit=1

 ID:                 79141
 Updated by:         cmb@php.net
 Reported by:        privat at ulrich-kapp dot de
 Summary:            Problem defining an array-type constant from a text
                     file
-Status:             Open
+Status:             Verified
-Type:               Bug
+Type:               Documentation Problem
-Package:            PHP Language Specification
+Package:            Scripting Engine problem
 Operating System:   Linux, other
 PHP Version:        7.4.1
 Block user comment: N
 Private report:     N

 New Comment:

Function calls are not allowed in constant expressions; this
should be clarified in the manual.


Previous Comments:
------------------------------------------------------------------------
[2020-01-20 09:48:23] 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);



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79141&edit=1


Thread (1 message)

  • cmb@php.net
  • Unknown Message
    • cmb@php.net
« previous php.doc.bugs (#17209) next »