diff --git a/PgCache_Environment.php b/PgCache_Environment.php index 52741cd4c..1af625595 100644 --- a/PgCache_Environment.php +++ b/PgCache_Environment.php @@ -482,8 +482,30 @@ private function wp_config_add_directive() { } $new_config_data = $this->wp_config_remove_from_content( $config_data ); + + /* + * Insert the WP_CACHE directive immediately after the opening PHP tag. When a + * strict_types declaration follows the tag, insert after that declaration instead, + * so the directive never displaces strict_types from being the first statement in + * the file (which is a fatal error). Comments between the tag and the declaration, + * and additional directives inside it (e.g. "declare(strict_types=1, ticks=1)"), + * are all tolerated. + */ $new_config_data = preg_replace( - '~<\?(php)?~', + '~ + <\?(?:php)? # Opening PHP tag: "wp_config_addon(), $new_config_data, 1 diff --git a/tests/test-wp-config-directive.php b/tests/test-wp-config-directive.php new file mode 100644 index 000000000..75b9c0e61 --- /dev/null +++ b/tests/test-wp-config-directive.php @@ -0,0 +1,185 @@ + 0 ? 1 : 0 );