php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76729 php -r command fails on valid PHP code, variable assignment from include
Submitted: 2018-08-10 20:32 UTC Modified: 2018-08-10 20:40 UTC
From: info at kelmmoyles dot com Assigned:
Status: Not a bug Package: PHP options/info functions
PHP Version: 7.1.20 OS: SmartOS / Solaris 11
Private report: No CVE-ID: None
 [2018-08-10 20:32 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-10 20:40 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2018-08-10 20:40 UTC] nikic@php.net
Most likely $config is interpreted as a variable by your shell and replaced by an empty string. Try using single quotes instead.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC