phpstan-wordpress icon indicating copy to clipboard operation
phpstan-wordpress copied to clipboard

ABSPATH bootstrap issue with 2.0.3

Open mikemanger opened this issue 1 month ago • 5 comments

We have a plugin file with some constants loaded in as a bootstrap file:

parameters:
	bootstrapFiles:
		- wp-content/plugins/my-plugin/my-plugin.php
	paths:
		- wp-content/plugins/my-plugin
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

define( 'PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );

/**
 * Used for TCPDF.
 */
require_once ABSPATH . 'vendor/autoload.php';

// ...

This worked fine in version 2.0.2 however in 2.0.3 it gives the error:

Note: Using configuration file /agent/build/phpstan.neon.dist.
Warning: require_once(/vendor/autoload.php): Failed to open stream: No such file or directory in /agent/build/wp-content/plugins/my-plugin/my-plugin.php on line 23
Error thrown in /agent/build/wp-content/plugins/my-plugin/my-plugin.php on line 23 while loading bootstrap file /agent/build/wp-content/plugins/my-plugin/my-plugin.php: Failed opening required '/vendor/autoload.php' (include_path='.:/usr/local/lib/php')
Script phpstan analyse --memory-limit=2048M handling the phpstan event returned with error code 1

It seems to be due to ABSPATH getting changed from ./ to / (1d6d3f3).

mikemanger avatar Nov 04 '25 14:11 mikemanger