@@ -37,19 +37,18 @@ export async function setupPlatformLevelMuPlugins(
3737 await php . mkdir ( '/internal/shared/mu-plugins' ) ;
3838
3939 if ( phpMajor < 7 ) {
40- // Overwrite auto_prepend_file.php to work around a PHP 5.6
41- // WASM parser bug: after require_once of 0-sqlite.php (which
42- // defines classes and globals), subsequent require_once calls
43- // get spurious "syntax error" at EOF. Using
44- // eval(file_get_contents()) instead avoids the issue.
40+ // Overwrite auto_prepend_file.php to add PHP 4 superglobal
41+ // polyfills that WP 1.0-2.5 needs. The default
42+ // auto_prepend_file only loads consts and preload files;
43+ // legacy PHP also needs the superglobals set up first.
4544 await php . writeFile (
4645 '/internal/shared/auto_prepend_file.php' ,
4746 `<?php
4847// Polyfill the PHP 4 superglobals that WP 1.0-2.5 still rely on.
49- // These were aliases of \ $_GET / \ $_POST / \ $_COOKIE / \ $_SERVER /
50- // \ $_FILES / \ $_ENV / \ $_REQUEST and were removed in PHP 5.4.
51- // Bind by reference so later writes to \ $_COOKIE (e.g. in
52- // auth bypass shims) are reflected in \ $HTTP_COOKIE_VARS that
48+ // These were aliases of $_GET / $_POST / $_COOKIE / $_SERVER /
49+ // $_FILES / $_ENV / $_REQUEST and were removed in PHP 5.4.
50+ // Bind by reference so later writes to $_COOKIE (e.g. in
51+ // auth bypass shims) are reflected in $HTTP_COOKIE_VARS that
5352// WP 1.0's get_currentuserinfo() reads.
5453$GLOBALS['HTTP_GET_VARS'] = &$_GET;
5554$GLOBALS['HTTP_POST_VARS'] = &$_POST;
@@ -59,8 +58,8 @@ if (isset($_FILES)) $GLOBALS['HTTP_POST_FILES'] = &$_FILES;
5958if (isset($_ENV)) $GLOBALS['HTTP_ENV_VARS'] = &$_ENV;
6059if (isset($_SESSION)) $GLOBALS['HTTP_SESSION_VARS'] = &$_SESSION;
6160// Also populate the top-level names that register_long_arrays +
62- // register_globals=On used to expose. WP 1.0 reads \ $PHP_SELF and
63- // \ $REMOTE_ADDR at the top level instead of \ $_SERVER[...].
61+ // register_globals=On used to expose. WP 1.0 reads $PHP_SELF and
62+ // $REMOTE_ADDR at the top level instead of $_SERVER[...].
6463if (isset($_SERVER['PHP_SELF'])) $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'];
6564if (isset($_SERVER['REMOTE_ADDR'])) $GLOBALS['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
6665if (isset($_SERVER['REQUEST_URI'])) $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
@@ -75,9 +74,7 @@ if(file_exists('/internal/shared/consts.json')) {
7574 }
7675}
7776foreach (glob('/internal/shared/preload/*.php') as $file) {
78- $code = file_get_contents($file);
79- $code = preg_replace('/^<\\\\?php\\\\s*/', '', $code);
80- eval($code);
77+ require_once $file;
8178}
8279`
8380 ) ;
@@ -110,8 +107,7 @@ function playground_load_mu_plugins() {
110107 sort( $mu_plugins );
111108 foreach ( $mu_plugins as $mu_plugin ) {
112109 // sqlite-database-integration.php is loaded separately
113- // by the preload lazy loader or db.php, using eval()
114- // to work around a PHP 5.6 WASM require_once parser bug.
110+ // by the preload lazy loader or db.php.
115111 if (strpos($mu_plugin, 'sqlite-database-integration') !== false) {
116112 continue;
117113 }
@@ -594,22 +590,6 @@ export async function preloadSqliteIntegration(
594590 / ^ ( a d d _ a c t i o n \( \s * \n ) / m,
595591 'if (function_exists("add_action")) $1'
596592 ) ;
597- // For PHP 5.6, replace require_once with eval in the
598- // mu-plugin to work around the WASM parser bug.
599- dbPhp = dbPhp . replace (
600- / ^ ( \s * ) r e q u i r e _ o n c e \s + ( [ ^ ; ] + ) ; / gm,
601- ( _match , indent , path ) => {
602- const trimmedPath = path . trim ( ) ;
603- if ( / ^ \$ \w + $ / . test ( trimmedPath ) ) {
604- return _match ;
605- }
606- return (
607- `${ indent } if(empty($GLOBALS['__evaled'][${ trimmedPath } ])){` +
608- `$GLOBALS['__evaled'][${ trimmedPath } ]=1;` +
609- `eval('?>' . file_get_contents(${ trimmedPath } ));}`
610- ) ;
611- }
612- ) ;
613593 }
614594 const dbPhpPath = joinPaths ( await php . documentRoot , 'wp-content/db.php' ) ;
615595 const SQLITE_MUPLUGIN_PATH =
@@ -635,20 +615,7 @@ if(file_exists(${phpVar(dbPhpPath)})) {
635615 }
636616 ` ;
637617
638- if ( phpMajor < 7 ) {
639- // NOTE: No closing ?> tag — PHP 5.6 WASM has a parser bug
640- // where ?> followed by <?php inside require_once'd files
641- // corrupts the parser state.
642- await php . writeFile (
643- SQLITE_MUPLUGIN_PATH ,
644- '<?php\n' + dbPhpGuard + dbPhp . replace ( / ^ < \? p h p \s * / , '' )
645- ) ;
646- } else {
647- await php . writeFile (
648- SQLITE_MUPLUGIN_PATH ,
649- `<?php\n${ dbPhpGuard } ?>` + dbPhp
650- ) ;
651- }
618+ await php . writeFile ( SQLITE_MUPLUGIN_PATH , `<?php\n${ dbPhpGuard } ?>` + dbPhp ) ;
652619 await php . writeFile (
653620 `/internal/shared/preload/0-sqlite.php` ,
654621 phpMajor < 7
@@ -699,22 +666,21 @@ if(!function_exists('mysqli_connect')) {
699666
700667/**
701668 * Builds the 0-sqlite.php preload content for legacy PHP (< 7).
702- * Uses eval() instead of require_once (PHP 5.6 WASM parser bug),
703- * includes MySQL/MySQLi stubs, str_* polyfills, and error suppression.
669+ * Includes MySQL/MySQLi stubs, str_* polyfills, and error suppression.
704670 */
705671function buildLegacySqlitePreload (
706672 dbPhpGuard : string ,
707673 muPluginPath : string ,
708674 phpVarFn : typeof phpVar
709675) : string {
710676 return `<?php
711- ${ dbPhpGuard }
677+ ${ dbPhpGuard } ?>
678+ <?php
712679${ SQLITE_PRELOAD_LOADER_CLASS (
713- // Legacy PHP: use eval() to work around WASM parser bug, and
714- // call reinitialize_sqlite() for old WordPress (< 3.0) where
680+ // Call reinitialize_sqlite() for old WordPress (< 3.0) where
715681 // the SQLite plugin's db_connect() is never called because old
716682 // wpdb does mysql_connect() inline.
717- `eval('?>' . file_get_contents( ${ phpVarFn ( muPluginPath ) } )) ;
683+ `require_once ${ phpVarFn ( muPluginPath ) } ;
718684 if (
719685 isset($GLOBALS['wpdb']) &&
720686 method_exists($GLOBALS['wpdb'], 'reinitialize_sqlite')
0 commit comments