?>
--EXPECTF--
-Notice: Undefined property: B::$test in %s on line %d
-
-Notice: Only variable references should be returned by reference in %s on line %d
-NULL
+Fatal error: Uncaught Error: Cannot access private property B::$test in %s:%d
+Stack trace:
+#0 %s(%d): A->__get('test')
+#1 {main}
+ thrown in %s on line %d
--- /dev/null
+--TEST--
+Property access errors should be thrown for overloaded properties protected by recursion guards
+--FILE--
+<?php
+
+function setProp($obj) {
+ $obj->prop = 42;
+}
+
+function getProp($obj) {
+ var_dump($obj->prop);
+}
+
+function unsetProp($obj) {
+ unset($obj->prop);
+}
+
+class Test {
+ private $prop;
+
+ public function __get($k) {
+ getProp($this);
+ }
+
+ public function __set($k, $v) {
+ setProp($this);
+ }
+
+ public function __unset($k) {
+ unsetProp($this);
+ }
+}
+
+$test = new Test;
+try {
+ $test->prop = "bar";
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump($test->prop);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ unset($test->prop);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Cannot access private property Test::$prop
+Cannot access private property Test::$prop
+Cannot access private property Test::$prop
}
OBJ_RELEASE(zobj);
goto exit;
- } else if (UNEXPECTED(ZSTR_VAL(name)[0] == '\0') && ZSTR_LEN(name) != 0) {
- zend_bad_property_name();
+ } else if (UNEXPECTED(IS_WRONG_PROPERTY_OFFSET(property_offset))) {
+ /* Trigger the correct error */
+ zend_get_property_offset(zobj->ce, name, 0, NULL);
+ ZEND_ASSERT(EG(exception));
retval = &EG(uninitialized_zval);
goto exit;
}
} else if (EXPECTED(!IS_WRONG_PROPERTY_OFFSET(property_offset))) {
goto write_std_property;
} else {
- if (UNEXPECTED(ZSTR_VAL(name)[0] == '\0') && ZSTR_LEN(name) != 0) {
- zend_bad_property_name();
- goto exit;
- }
+ /* Trigger the correct error */
+ zend_get_property_offset(zobj->ce, name, 0, NULL);
+ ZEND_ASSERT(EG(exception));
+ goto exit;
}
- } else if (EXPECTED(!IS_WRONG_PROPERTY_OFFSET(property_offset))) {
+ } else {
+ ZEND_ASSERT(!IS_WRONG_PROPERTY_OFFSET(property_offset));
write_std_property:
if (Z_REFCOUNTED_P(value)) {
if (Z_ISREF_P(value)) {
(*guard) |= IN_UNSET; /* prevent circular unsetting */
zend_std_call_unsetter(zobj, name);
(*guard) &= ~IN_UNSET;
+ } else if (UNEXPECTED(IS_WRONG_PROPERTY_OFFSET(property_offset))) {
+ /* Trigger the correct error */
+ zend_get_property_offset(zobj->ce, name, 0, NULL);
+ ZEND_ASSERT(EG(exception));
+ goto exit;
} else {
- if (UNEXPECTED(ZSTR_VAL(name)[0] == '\0') && ZSTR_LEN(name) != 0) {
- zend_bad_property_name();
- goto exit;
- }
+ /* Nothing to do: The property already does not exist. */
}
}