Bug #76729 [Opn->Nab]: php -r command fails on valid PHP code, variable assignment from include
Edit report at https://bugs.php.net/bug.php?id=76729&edit=1
ID: 76729
Updated by: nikic@php.net
Reported by: info at kelmmoyles dot com
Summary: php -r command fails on valid PHP code, variable
assignment from include
-Status: Open
+Status: Not a bug
Type: Bug
Package: PHP options/info functions
Operating System: SmartOS / Solaris 11
PHP Version: 7.1.20
Block user comment: N
Private report: N
New Comment:
Most likely $config is interpreted as a variable by your shell and replaced by an empty string. Try
using single quotes instead.
Previous Comments:
------------------------------------------------------------------------
[2018-08-10 20:32:17] info at kelmmoyles dot com
Description:
------------
php -r "$config = include 'LocalConfiguration.php'"
fails with:
PHP Parse error: syntax error, unexpected '=', expecting end of file in Command line code
on line 1
even though the code itself is valid PHP that runs fine when executed from within a PHP file, e.g.:
config.php
<?php
$config = include 'LocalConfiguration.php';
?>
and then run:
php config.php
FYI: The file referenced above is a config file from the Typo3 CMS, where its config in stored in an
array, e.g.:
https://forge.typo3.org/attachments/23893/LocalConfiguration.php
Actual OS used is "SunOS host 5.11 joyent_20180315T080815Z" with PHP from pkgsrc:
PHP 7.1.13 (cli) (built: Apr 8 2018 19:57:49) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.13, Copyright (c) 1999-2017, by Zend Technologies
Test script:
---------------
- download https://forge.typo3.org/attachments/download/23893/LocalConfiguration.php
to a local directory
- in that same directory run:
php -r "$config = include 'LocalConfiguration.php'"
Expected result:
----------------
same behavior regardless whether the PHP code is read/executed from a PHP file or executed via the
command line using "php -r"
Actual result:
--------------
"php -r" execution fails with this code
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76729&edit=1
Thread (2 messages)