Skip to content

Commit 7d12115

Browse files
schlesseraclaude
andcommitted
Keep the shared opcode cache from changing what the code does
The optimizer evaluates calls like function_exists() at compile time, so code cached by a process with the default settings skipped the ini_set() fallback of WP-CLI in a process that disables it. Cache the code without optimizing it. Behat and Composer restart without Xdebug, which clears PHP_INI_SCAN_DIR, so the WP-CLI processes lost the scan directory of the system, and the extensions configured there. Take the original directories from the restart settings instead. Also leave out SQLITE_ENABLE_UPDATE_DELETE_LIMIT, which needs a parser the amalgamation does not have. Fixes #416. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e4e99fc commit 7d12115

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎features/testing.feature‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,14 @@ Feature: Test that WP-CLI loads.
208208
C:\Windows
209209
"""
210210

211+
212+
@skip-windows
213+
Scenario: Run WP-CLI with a disabled function after it ran without
214+
Given an empty directory
215+
When I run `wp cli version`
216+
And I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--ddisable_functions=ini_set} cli info`
217+
Then the return code should be 0
218+
And STDOUT should contain:
219+
"""
220+
PHP binary
221+
"""

‎src/Context/FeatureContext.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,30 @@ private static function get_php_tuning_env_variables(): array {
600600
$excluded = array_unique( array_filter( [ $temp_dir, realpath( $temp_dir ) ] ) );
601601
file_put_contents( "{$config_dir}/opcache-blacklist.txt", implode( "/\n", $excluded ) . "/\n" );
602602

603+
// The optimizer bakes in what it finds at compile time, such as whether a function exists,
604+
// which differs between processes with other settings, such as disabled functions.
603605
$ini = [
604606
'opcache.enable_cli=1',
605607
"opcache.file_cache={$cache_dir}",
606608
'opcache.file_cache_only=1',
609+
'opcache.optimization_level=0',
607610
"opcache.blacklist_filename={$config_dir}/opcache-blacklist.txt",
608611
];
609612
file_put_contents( "{$config_dir}/wp-cli-tests.ini", implode( "\n", $ini ) . "\n" );
610613

611614
// Add to the directories PHP scans for configuration files rather than replacing them.
612615
$scan_dirs = getenv( 'PHP_INI_SCAN_DIR' );
616+
617+
// Behat and Composer restart without Xdebug through composer/xdebug-handler, which clears
618+
// the directories, and keeps the original ones in its settings, with "*" if there were none.
619+
$restart_settings = getenv( 'XDEBUG_HANDLER_SETTINGS' );
620+
if ( '' === $scan_dirs && is_string( $restart_settings ) ) {
621+
$settings = explode( '|', $restart_settings );
622+
if ( isset( $settings[2] ) ) {
623+
$scan_dirs = '*' === $settings[2] ? false : $settings[2];
624+
}
625+
}
626+
613627
if ( false === $scan_dirs ) {
614628
$scan_dirs = PHP_CONFIG_FILE_SCAN_DIR;
615629
}

‎utils/docker/Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ RUN if dpkg --compare-versions "$(dpkg-query -W -f '${Version}' libsqlite3-0)" l
4040
&& [ "$(openssl dgst -sha3-256 -r sqlite.tar.gz | cut -d' ' -f1)" = "${SQLITE_SHA3_256}" ] \
4141
&& tar xzf sqlite.tar.gz \
4242
&& cd "sqlite-autoconf-${SQLITE_VERSION}" \
43-
&& CFLAGS="-O2 -DSQLITE_ALLOW_ROWID_IN_VIEW -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS3_TOKENIZER -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_LOAD_EXTENSION -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_MAX_SCHEMA_RETRY=25 -DSQLITE_SECURE_DELETE -DSQLITE_SOUNDEX -DSQLITE_USE_URI=1" \
43+
&& CFLAGS="-O2 -DSQLITE_ALLOW_ROWID_IN_VIEW -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS3_TOKENIZER -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_LOAD_EXTENSION -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_MAX_SCHEMA_RETRY=25 -DSQLITE_SECURE_DELETE -DSQLITE_SOUNDEX -DSQLITE_USE_URI=1" \
4444
./configure --prefix=/usr/local --disable-static > /dev/null \
4545
&& make -j"$(nproc)" > /dev/null \
4646
&& make install > /dev/null \

0 commit comments

Comments
 (0)