Skip to content

Autovivication prototype and investigation notes #17

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

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 29 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,14 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
return;
}
}
if (Z_TYPE_P(container) >= IS_NULL) {
zend_error(E_DEPRECATED,
"Automatic conversion of %s to array on field assignment is deprecated", Z_TYPE_P(container) == IS_NULL ? "null" : "false");
if (UNEXPECTED(EG(exception))) {
ZVAL_UNDEF(result);
return;
}
}
array_init(container);
goto fetch_from_array;
} else {
Expand Down Expand Up @@ -2354,6 +2362,14 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
ZVAL_UNDEFINED_OP1();
}
if (type != BP_VAR_UNSET) {
if (Z_TYPE_P(container) >= IS_NULL) {
zend_error(E_DEPRECATED,
"Automatic conversion of %s to array on field assignment is deprecated", Z_TYPE_P(container) == IS_NULL ? "null" : "false");
if (UNEXPECTED(EG(exception))) {
ZVAL_UNDEF(result);
return;
}
}
array_init(container);
goto fetch_from_array;
} else {
Expand Down Expand Up @@ -2863,6 +2879,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
name = zval_get_tmp_string(prop_ptr, &tmp_name);
}
ptr = zobj->handlers->get_property_ptr_ptr(zobj, name, type, cache_slot);
// XXX this will create the property if it does not exist and set the type to IS_NULL (only if it is a dynamic property)
if (NULL == ptr) {
ptr = zobj->handlers->read_property(zobj, name, type, cache_slot, result);
if (ptr == result) {
Expand All @@ -2882,6 +2899,18 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c

ZVAL_INDIRECT(result, ptr);
if (flags) {
if (flags == ZEND_FETCH_DIM_WRITE) {
// XXX this will emit a false positive for `$obj->unsetProp[] = 123;` because of the conversion of undefined to the null array.
if (Z_TYPE_P(ptr) >= IS_NULL && Z_TYPE_P(ptr) <= IS_FALSE) {
zend_error(E_DEPRECATED,
"Automatic conversion of %s to array on property field assignment is deprecated", Z_TYPE_P(ptr) == IS_NULL ? "null" : "false");
if (UNEXPECTED(EG(exception))) {
ZVAL_ERROR(result);
goto end;
}
}
}

zend_property_info *prop_info;

if (prop_op_type == IS_CONST) {
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
rebuild_object_properties(zobj);
}
retval = zend_hash_update(zobj->properties, name, &EG(uninitialized_zval));
// NOTE: retval will have type IS_NULL
/* Notice is thrown after creation of the property, to avoid EG(std_property_info)
* being overwritten in an error handler. */
if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
Expand Down
9 changes: 9 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,15 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
FREE_OP_DATA();
}
} else if (EXPECTED(Z_TYPE_P(object_ptr) <= IS_FALSE)) {
#if OP1_TYPE == IS_CV
if (Z_TYPE_P(object_ptr) >= IS_NULL) {
zend_error(E_DEPRECATED,
"Automatic conversion of %s to array on field assignment is deprecated", Z_TYPE_P(object_ptr) == IS_NULL ? "null" : "false");
if (UNEXPECTED(EG(exception))) {
ZEND_VM_C_GOTO(assign_dim_error);
}
}
#endif
if (Z_ISREF_P(orig_object_ptr)
&& ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(orig_object_ptr))
&& !zend_verify_ref_array_assignable(Z_REF_P(orig_object_ptr))) {
Expand Down
Loading