--- /dev/null
+--TEST--
+Bug #37667 (Object is not added into array returned by __get)
+--FILE--
+<?php
+
+class Test
+{
+ protected $property = array('foo' => 'bar');
+
+ function __get($name)
+ {
+ return $this->property;
+ }
+}
+
+$obj = new Test;
+
+var_dump($obj->property['foo']);
+var_dump($obj->property[2]);
+
+var_dump($obj);
+
+$obj->property[] = 1;
+$obj->property[] = 2;
+
+var_dump($obj);
+
+?>
+===DONE===
+--EXPECTF--
+string(3) "bar"
+
+Notice: Undefined offset: 2 in %sbug37667.php on line %d
+NULL
+object(Test)#%d (1) {
+ ["property:protected"]=>
+ array(1) {
+ ["foo"]=>
+ string(3) "bar"
+ }
+}
+
+Fatal error: Cannot use array returned from Test::__get('property') in write context in %sbug37667.php on line %d
char *res = estrdup(""), **str = &res, *s_tmp;
int res_len = 0, *len = &res_len, num = 0;
- trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
+ trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, BP_VAR_R TSRMLS_CC);
zend_hash_apply_with_arguments(Z_ARRVAL_P(trace), (apply_func_args_t)_build_trace_string, 3, str, len, &num);
s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 7 + 1);
offset_key = "";
offset_key_length = 0;
goto fetch_string_dim;
+
case IS_STRING:
offset_key = dim->value.str.val;
zval *ptr;
if (Z_OBJ_HT_P(container)->read_property &&
- (ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, BP_VAR_W TSRMLS_CC)) != NULL) {
+ (ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type TSRMLS_CC)) != NULL) {
if (result) {
result->var.ptr = ptr;
result->var.ptr_ptr = &result->var.ptr;
}
} else if (Z_OBJ_HT_P(container)->read_property) {
if (result) {
- result->var.ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, BP_VAR_W TSRMLS_CC);
+ result->var.ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type TSRMLS_CC);
result->var.ptr_ptr = &result->var.ptr;
}
} else {
zval_ptr_dtor(&tmp_member);
(*retval)->refcount--;
}
+ if (*retval && (type == BP_VAR_W || type == BP_VAR_RW) && Z_TYPE_PP(retval) == IS_ARRAY) {
+ zend_error(E_ERROR, "Cannot use array returned from %s::__get('%s') in write context", zobj->ce->name, Z_STRVAL_P(member));
+ }
return *retval;
}