Description
Introduced with PR #41786 which added a class constant WP_Theme_JSON_6_1::VALID_ELEMENT_PSEUDO_SELECTORS to define an array of valid pseudo selectors for a list of elements.
When activating (or updating) Gutenberg plugin, a fatal error happens:
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in ../wp-content/plugins/gutenberg/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php on line 190
Why?
Before PHP 7.0, isset() does not work with constants (see it in action here https://3v4l.org/lrFo3#v5.6.40) and will throw a parsing error (which is fatal). Per the warning in the PHP manual
Warning
isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.
In PHP 5.6, isset() works with variables, not constants.
How to resolve?
The class is defining the data type for each element as an array of pseudos. It has control over the structure. Therefore, array_key_exists() can be used instead to check if the element is defined in the constant. Why? array_key_exists() is a native PHP function that specifically checks for the existence of keys. It's the appropriate function for this need.
Step-by-step reproduction instructions
- Set your environment to use PHP 5.6 (how to do this depends upon the localhost app/tooling you're using).
- Log into the admin area.
- Go to Plugins > Add New.
- Install the Gutenberg plugin.
- Active the plugin.
Screenshots, screen recording, code snippet

Environment info
- WordPress version: 6.0
- Gutenberg plugin: 13.6.0
- PHP version: 5.6.39
- Web server: nginx
- Plugins: Only Gutenberg
- Theme: Twenty Twenty-Two (TT2)
- localhost app: Local and wp-env
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Description
Introduced with PR #41786 which added a class constant
WP_Theme_JSON_6_1::VALID_ELEMENT_PSEUDO_SELECTORSto define an array of valid pseudo selectors for a list of elements.When activating (or updating) Gutenberg plugin, a fatal error happens:
Why?
Before PHP 7.0,
isset()does not work with constants (see it in action here https://3v4l.org/lrFo3#v5.6.40) and will throw a parsing error (which is fatal). Per the warning in the PHP manualIn PHP 5.6,
isset()works with variables, not constants.How to resolve?
The class is defining the data type for each element as an array of pseudos. It has control over the structure. Therefore,
array_key_exists()can be used instead to check if the element is defined in the constant. Why?array_key_exists()is a native PHP function that specifically checks for the existence of keys. It's the appropriate function for this need.Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes