Skip to content

Remove IS_STATIC_VAR_UNINITIALIZED #15227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
zend_std_get_properties(). Use zend_std_get_properties_ex() or
zend_std_get_properties() instead.

* Removed IS_STATIC_VAR_UNINITIALIZED constant. Check for IS_NULL in the
static_variables array instead.

========================
2. Build system changes
========================
Expand Down
21 changes: 21 additions & 0 deletions Zend/tests/static_variables_throwing_initializer.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Static variable with throwing initializer
--FILE--
<?php

function foo($throw) {
static $a = $throw ? (throw new Exception('Throwing from foo()')) : 42;
return $a;
}

try {
var_dump(foo(true));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
var_dump(foo(false));

?>
--EXPECT--
Throwing from foo()
int(42)
1 change: 0 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5483,7 +5483,6 @@ static void zend_compile_static_var(zend_ast *ast) /* {{{ */
zend_op *opline;

zval *placeholder_ptr = zend_hash_update(CG(active_op_array)->static_variables, var_name, &EG(uninitialized_zval));
Z_TYPE_EXTRA_P(placeholder_ptr) |= IS_STATIC_VAR_UNINITIALIZED;
uint32_t placeholder_offset = (uint32_t)((char*)placeholder_ptr - (char*)CG(active_op_array)->static_variables->arData);

uint32_t static_def_jmp_opnum = get_next_op_number();
Expand Down
5 changes: 0 additions & 5 deletions Zend/zend_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,6 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
/* zval.u1.v.type_flags */
#define IS_TYPE_REFCOUNTED (1<<0)
#define IS_TYPE_COLLECTABLE (1<<1)
/* Used for static variables to check if they have been initialized. We can't use IS_UNDEF because
* we can't store IS_UNDEF zvals in the static_variables HashTable. This needs to live in type_info
* so that the ZEND_ASSIGN overrides it but is moved to extra to avoid breaking the Z_REFCOUNTED()
* optimization that only checks for Z_TYPE_FLAGS() without `& (IS_TYPE_COLLECTABLE|IS_TYPE_REFCOUNTED)`. */
#define IS_STATIC_VAR_UNINITIALIZED (1<<0)

#if 1
/* This optimized version assumes that we have a single "type_flag" */
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -9110,7 +9110,7 @@ ZEND_VM_HANDLER(203, ZEND_BIND_INIT_STATIC_OR_JMP, CV, JMP_ADDR)
ZEND_ASSERT(GC_REFCOUNT(ht) == 1);

value = (zval*)((char*)ht->arData + opline->extended_value);
if (Z_TYPE_EXTRA_P(value) & IS_STATIC_VAR_UNINITIALIZED) {
if (Z_TYPE_P(value) == IS_NULL) {
ZEND_VM_NEXT_OPCODE();
} else {
SAVE_OPLINE();
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading