Description
wpify/scoper is incorrectly adding namespace prefixes to constant names inside defined() function calls. PHP constants do not support namespaces, so this breaks the functionality.
Current Behavior
// Before scoping
if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
// ...
}
// After scoping (incorrect)
if (defined('My\Prefix\WP_DEBUG_LOG') && WP_DEBUG_LOG) {
// ...
}
The defined('My\Prefix\WP_DEBUG_LOG') call will always return false because the actual constant is named WP_DEBUG_LOG, not My\Prefix\WP_DEBUG_LOG.
Expected Behavior
Constant names inside defined() calls should remain unchanged:
// After scoping (correct)
if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
// ...
}
Workaround
Add this patcher to scoper.custom.php:
function customize_php_scoper_config(array $config): array {
$config['patchers'][] = static function (string $filePath, string $prefix, string $content): string {
return str_replace("defined('{$prefix}\\", "defined('", $content);
};
return $config;
}
Environment
- wpify/scoper: 3.2
- PHP: 8.2
composer.json
{
"require": {
"php": ">=8.2"
},
"require-dev": {
"wpify/scoper": "^3.2"
},
"config": {
"allow-plugins": {
"wpify/scoper": true
},
"optimize-autoloader": true,
"platform": {
"php": "8.2.9999"
}
},
"extra": {
"wpify-scoper": {
"prefix": "My\\Prefix"
}
}
}
composer-deps.json
{
"require": {
"inpsyde/wonolog": "2.x-dev",
"thecodingmachine/safe": "^3.3",
"wecodemore/wordpress-early-hook": "^1.1.0"
},
"config": {
"platform": {
"php": "8.2.9999"
}
}
}
Description
wpify/scoper is incorrectly adding namespace prefixes to constant names inside
defined()function calls. PHP constants do not support namespaces, so this breaks the functionality.Current Behavior
The
defined('My\Prefix\WP_DEBUG_LOG')call will always returnfalsebecause the actual constant is namedWP_DEBUG_LOG, notMy\Prefix\WP_DEBUG_LOG.Expected Behavior
Constant names inside
defined()calls should remain unchanged:Workaround
Add this patcher to
scoper.custom.php:Environment
composer.json
{ "require": { "php": ">=8.2" }, "require-dev": { "wpify/scoper": "^3.2" }, "config": { "allow-plugins": { "wpify/scoper": true }, "optimize-autoloader": true, "platform": { "php": "8.2.9999" } }, "extra": { "wpify-scoper": { "prefix": "My\\Prefix" } } }composer-deps.json
{ "require": { "inpsyde/wonolog": "2.x-dev", "thecodingmachine/safe": "^3.3", "wecodemore/wordpress-early-hook": "^1.1.0" }, "config": { "platform": { "php": "8.2.9999" } } }