Ingap.dev - A Personal Dev Blog

Dress for the job you want, not the job you have.

Published on Saturday 5 March 2022

Tags: php1 wordpress1

[SOLVED] Fatal error: Uncaught TypeError: get_class(): Argument #1 ($object) must be of type object, null given […] in crayon_langs.class.php on line 414

Solving error message of the Wordpress Plugin 'Crayon Syntax Highlighter'


The above stated error concerns the plugin Crayon Syntax Highlighter, a plugin used to include code in wordpress posts from different programming languages, since it’s not being updated to be compatible with PHP versions later than 7.2.

To solve this particular problem, go to the line given in the error message, i.e. to wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php (line 414) and wrap the code with an additional check on $element to know wheter it’s an object or not, i.e. replace this:

if (@get_class($element) == CRAYON_ELEMENT_CLASS) {
    $this->elements[$name] = $element;
}

with this:

else if (is_object($element)){
    if (@get_class($element) == CRAYON_ELEMENT_CLASS) {
        $this->elements[$name] = $element;
    }
}