diff --git a/NEWS b/NEWS index 9953a673164..6af7477ac66 100644 --- a/NEWS +++ b/NEWS @@ -39,6 +39,7 @@ PHP NEWS - Opcache: . Fixed bug #74431 (foreach infinite loop). (Nikita) + . Fixed bug #74442 (Opcached version produces a nested array). (Nikita) - OpenSSL: . Fixed bug #74341 (openssl_x509_parse fails to parse ASN.1 UTCTime without diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c index 4e4260660c0..027814b5cd5 100644 --- a/ext/opcache/Optimizer/dfa_pass.c +++ b/ext/opcache/Optimizer/dfa_pass.c @@ -366,6 +366,12 @@ static zend_bool opline_supports_assign_contraction( && (opline->op2_type != IS_CV || opline->op2.var != cv_var); } + if (opline->opcode == ZEND_CAST) { + /* CAST to array/object may initialize the result to an empty array/object before + * reading the expression. */ + return opline->extended_value != IS_ARRAY && opline->extended_value != IS_OBJECT; + } + return 1; } diff --git a/ext/opcache/tests/bug74442.phpt b/ext/opcache/tests/bug74442.phpt new file mode 100644 index 00000000000..6b02d494a08 --- /dev/null +++ b/ext/opcache/tests/bug74442.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #74442: Opcached version produces a nested array +--FILE-- +addField('Field_Integer'); +} catch (Throwable $ex) { + echo "CAUGHT EXCEPTION"; + echo (string)$ex; +} + +?> +--EXPECT-- +4