On Prestashop, I have a production and staging server. I want to activate debug mode on staging environment.
I can use $_SERVER['SERVER_NAME']
to identify my environment, so I can define my constant like this :
if (! defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', $_SERVER['SERVER_NAME'] === 'staging.domain.name');
}
But it’s not working, the debug mode is not enabled.
When I’m testing my values :
var_dump(! defined('_PS_MODE_DEV_')); // true
if (! defined('_PS_MODE_DEV_')) {
var_dump($_SERVER['SERVER_NAME'] === 'staging.domain.name'); // true
define('_PS_MODE_DEV_', $_SERVER['SERVER_NAME'] === 'staging.domain.name');
}
var_dump(_PS_MODE_DEV_); // true
Everything looks good, I don’t understand why the debug mode stills disabled.
I thought it was a problem with the mode itself, but if I set like this :
if (! defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', true);
}
It works, the debug mode is enabled…
Maybe there is some limitation with define()
? (I cannot find an example using an expression).
So, I tried like this :
if (! defined('_PS_MODE_DEV_')) {
if ($_SERVER['SERVER_NAME'] === 'staging.domain.name') {
define('_PS_MODE_DEV_', true);
}
else {
define('_PS_MODE_DEV_', false);
}
}
That works too, the debug mode is enabled on staging. HOWEVER, the debug mode is enabled on production too !
I am completely lost, because if I set even like this :
if (! defined('_PS_MODE_DEV_')) {
if (false) {
define('_PS_MODE_DEV_', true);
}
else {
define('_PS_MODE_DEV_', false);
}
}
The debug mode stills enabled… I have no idea what is going on here. For me, it looks like PHP ignores my condition, and takes always the first define().
Could someone give me some ideas to understand what happens here ?