Modx PHP warning: constant(): Couldn't find constant 32759

Summary

Error thrown by modProcessor

Step to reproduce

Clean install of 2.7.1-pl and migx. Error reporting setting default.

Observed behavior

refreshing a migx cmp throws as many lines of the same error as the number of records shown in the grid

Expected behavior

How it should behave after following the steps above.
Dont throw errors :laughing:

Environment

MODX version tagged when creating the issue, Apache or NGINX with version, MySQL version, browser, etc. Any relevant information.

In response to this thread https://forums.modx.com/thread/104914/help-troubleshooting-warning-constant-couldn-t-find-constant-32759-in-modx-core-model-modx-modx-class-php-on-line-690 where a member described the problem as occurring on a regularly updated installation, i noticed the same behavior on a fresh install of 2.7.1pl

The error thrown is:
(ERROR @ /var/www/vhosts/laurajacobs.es/core/model/modx/modx.class.php : 679) PHP warning: constant(): Couldn’t find constant 32759
[2019-10-16 15:15:36] (ERROR @ /var/www/vhosts/mydomain.es/core/model/modx/modx.class.php : 679) PHP warning: constant(): Couldn’t find constant 32759

The line is: $debug = (is_int($debug) ? $debug : defined($debug) ? intval(constant($debug)) : 0);

I’ve thougth about it and figured it should just work cause defined debug should test for the constant being set. And it is. So maybe the ternary (which is a bit hard to read(well for me at least)) is a little borked.

So I’d figure a simple solution to this one which helped me out, and maybe OP as well is the little ditty below.

if(is_int($debug))
{
    // nothing
}
else
{
    if(defined($debug))
    {
	$debug = (int) $constant($debug) ;
    }
    else
    {
        $debug = 0 ;
    }
}

In all fairness as far as I can tell the notice doesn’t prevent anything from functioning properly and when going live error reporting will be set to 0 anyway. Just figured you guys like to know. Also if my ‘fix’ is flawed too I’d like to hear about it.

1 Like

I wonder… does the notice go away if you change the ternary to this?

$debug = is_int($debug) ? $debug : (defined($debug) ? intval(constant($debug)) : 0);

Or slightly more readable:

$debug = is_int($debug) 
    ? $debug 
    : (
        defined($debug) 
        ? intval(constant($debug)) 
        : 0
    );
1 Like