ZVAL_COPY(&data, value_ptr);
zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
}
+ if (zend_string_equals_literal(Z_STR_P(entry), "this")) {
+ zend_object *object = zend_get_this_object(EG(current_execute_data));
+ if (object) {
+ GC_REFCOUNT(object)++;
+ ZVAL_OBJ(&data, object);
+ zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
+ }
+ }
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
if ((Z_ARRVAL_P(entry)->u.v.nApplyCount > 1)) {
php_error_docref(NULL, E_WARNING, "recursion detected");
--- /dev/null
+--TEST--
+compact() without object context
+--FILE--
+<?php
+
+var_dump(
+ (new class {
+ function test(){
+ return (static function(){ return compact('this'); })();
+ }
+ })->test()
+);
+
+var_dump(compact('this'));
+
+var_dump((function(){ return compact('this'); })());
+
+?>
+--EXPECT--
+array(0) {
+}
+array(0) {
+}
+array(0) {
+}
--- /dev/null
+--TEST--
+compact() with object context
+--FILE--
+<?php
+
+var_dump(
+ (new class {
+ function test(){
+ return compact('this');
+ }
+ })->test()
+);
+
+var_dump(
+ (new class {
+ function test(){
+ return compact([['this']]);
+ }
+ })->test()
+);
+
+var_dump(
+ (new class {
+ function test(){
+ return (function(){ return compact('this'); })();
+ }
+ })->test()
+);
+
+?>
+--EXPECT--
+array(1) {
+ ["this"]=>
+ object(class@anonymous)#1 (0) {
+ }
+}
+array(1) {
+ ["this"]=>
+ object(class@anonymous)#1 (0) {
+ }
+}
+array(1) {
+ ["this"]=>
+ object(class@anonymous)#1 (0) {
+ }
+}