From 2aac65c4badc94875cd4d6d916c3fe5a834515eb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 3 Feb 2026 08:17:50 +0100 Subject: [PATCH 1/2] MutatingScope: prevent unnecessary scope re-creation after openssl* calls --- src/Analyser/MutatingScope.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 5af1a88189..f002343e7f 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -573,10 +573,7 @@ public function afterClearstatcacheCall(): self public function afterOpenSslCall(string $openSslFunctionName): self { - $expressionTypes = $this->expressionTypes; - $nativeExpressionTypes = $this->nativeExpressionTypes; - - if (in_array($openSslFunctionName, [ + if (!in_array($openSslFunctionName, [ 'openssl_cipher_iv_length', 'openssl_cms_decrypt', 'openssl_cms_encrypt', @@ -631,10 +628,14 @@ public function afterOpenSslCall(string $openSslFunctionName): self 'openssl_x509_read', 'openssl_x509_verify', ], true)) { - unset($expressionTypes['\openssl_error_string()']); - unset($nativeExpressionTypes['\openssl_error_string()']); + return $this; } + $expressionTypes = $this->expressionTypes; + $nativeExpressionTypes = $this->nativeExpressionTypes; + unset($expressionTypes['\openssl_error_string()']); + unset($nativeExpressionTypes['\openssl_error_string()']); + return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), From d910e5f6eb066c739220f6609ab866a212bf1247 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 3 Feb 2026 08:21:46 +0100 Subject: [PATCH 2/2] MutatingScope: prevent unnecessary scope re-creation after clearstatcache() --- src/Analyser/MutatingScope.php | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index f002343e7f..0a48658184 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -514,6 +514,8 @@ public function afterExtractCall(): self public function afterClearstatcacheCall(): self { + $changed = false; + $expressionTypes = $this->expressionTypes; $nativeExpressionTypes = $this->nativeExpressionTypes; foreach (array_keys($expressionTypes) as $exprString) { @@ -547,10 +549,15 @@ public function afterClearstatcacheCall(): self unset($expressionTypes[$exprString]); unset($nativeExpressionTypes[$exprString]); + $changed = true; continue 2; } } + if (!$changed) { + return $this; + } + return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), @@ -573,7 +580,19 @@ public function afterClearstatcacheCall(): self public function afterOpenSslCall(string $openSslFunctionName): self { - if (!in_array($openSslFunctionName, [ + $expressionTypes = $this->expressionTypes; + $nativeExpressionTypes = $this->nativeExpressionTypes; + + $errorStringFunction = '\openssl_error_string()'; + if ( + !array_key_exists($errorStringFunction, $expressionTypes) + && !array_key_exists($errorStringFunction, $nativeExpressionTypes) + ) { + return $this; + } + + $changed = false; + if (in_array($openSslFunctionName, [ 'openssl_cipher_iv_length', 'openssl_cms_decrypt', 'openssl_cms_encrypt', @@ -628,13 +647,14 @@ public function afterOpenSslCall(string $openSslFunctionName): self 'openssl_x509_read', 'openssl_x509_verify', ], true)) { - return $this; + unset($expressionTypes[$errorStringFunction]); + unset($nativeExpressionTypes[$errorStringFunction]); + $changed = true; } - $expressionTypes = $this->expressionTypes; - $nativeExpressionTypes = $this->nativeExpressionTypes; - unset($expressionTypes['\openssl_error_string()']); - unset($nativeExpressionTypes['\openssl_error_string()']); + if (!$changed) { + return $this; + } return $this->scopeFactory->create( $this->context,