Skip to content

Defining constant with __FILE__ in name breaks execution #5332

Closed

Description

@aaemnnosttv

Bug Report

Describe the current, buggy behavior

Defining a constant in wp-config.php that includes __FILE__ in the name of the constant, causes wp-cli to fail with this error message:

Parse error: syntax error, unexpected 'var' (T_VAR) in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1197) : eval()'d code on line 66

Using latest v2.4.0 phar executable.

Describe how other contributors can replicate this bug

  1. Add this line to wp-config.php
    define( 'WP_CONFIG__FILE__', __FILE__ );
  2. Run wp
  3. See the above error, command fails

Describe what you expect as the correct outcome

I would expect the wp command list to display.

Let us know what environment you are running this on

OS:	Linux 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64
Shell:	
PHP binary:	/usr/local/bin/php
PHP version:	7.3.9
php.ini used:	/usr/local/etc/php/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/var/www/html
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.4.0

Activity

  1. added this to the 2.5.0 milestone on Feb 5, 2020
  2. schlessera commented on Feb 5, 2020

    @schlessera
    Member

    The code in

    wp-cli/php/utils.php

    Lines 614 to 624 in d68399b

    function replace_path_consts( $source, $path ) {
    $replacements = array(
    '__FILE__' => "'$path'",
    '__DIR__' => "'" . dirname( $path ) . "'",
    );
    $old = array_keys( $replacements );
    $new = array_values( $replacements );
    return str_replace( $old, $new, $source );
    }
    is too primitive and easily breaks.

    We should use the code from wp-cli/eval-command#44 and provide it as an improved centralized helper here, and then make eval-file reuse that helper.

    • Port code from eval-file to wp-cli/wp-cli
    • After next wp-cli/wp-cli release: Use Utils/replace_path_consts() in eval-file
    • After next wp-cli/wp-cli release: Bump version requirement of wp-cli/wp-cli in wp-cli/eval-command
  3. schlessera commented on May 12, 2021

    @schlessera
    Member

    This should be resolved with latest master and fixed in upcoming v2.5.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions