Skip to content

Commit 26cb5b2

Browse files
committed
check if it's a reference
1 parent 666e493 commit 26cb5b2

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

ext/reflection/php_reflection.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6731,7 +6731,12 @@ ZEND_METHOD(ReflectionProperty, isReadable)
67316731
zval member;
67326732
ZVAL_STR(&member, ref->unmangled_name);
67336733
zend_call_known_instance_method_with_1_params(ce->__isset, obj, return_value, &member);
6734-
zend_unwrap_reference(return_value);
6734+
6735+
// if it's a reference, unwrap
6736+
if (Z_TYPE_P(return_value) == IS_REFERENCE) {
6737+
zend_unwrap_reference(return_value);
6738+
}
6739+
67356740
*guard &= ~ZEND_GUARD_PROPERTY_ISSET;
67366741
OBJ_RELEASE(obj);
67376742
return;

ext/reflection/tests/gh22000.phpt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
GH-22000 - Ensure __isset is not returning a reference in ReflectionProperty::isReadable()
33
--FILE--
44
<?php
5-
class TestClass {
6-
public int $a;
5+
class TestClass1 {
6+
public int $a = 1;
77
public int $b;
88
public int $c;
99

@@ -12,8 +12,25 @@ class TestClass {
1212
unset($this->c);
1313
}
1414

15+
public function __isset($name) {
16+
return $name === 'b';
17+
}
18+
19+
public function __get($name) {}
20+
}
21+
22+
class TestClass2 {
23+
public int $d;
24+
public int $e;
25+
public int $f;
26+
27+
public function __construct() {
28+
unset($this->e);
29+
unset($this->f);
30+
}
31+
1532
public function &__isset($name) {
16-
return $name === 'c';
33+
return $name === 'f';
1734
}
1835

1936
public function __get($name) {}
@@ -28,13 +45,17 @@ function test($class) {
2845
}
2946
}
3047

31-
test('TestClass');
48+
test('TestClass1');
49+
test('TestClass2');
3250
?>
3351
--EXPECTF--
34-
a from global:bool(false)
35-
b from global:
36-
Notice: Only variable references should be returned by reference in /home/zaaarf/dev/irl/c/php/ext/reflection/tests/gh22000.php on line 13
52+
a from global:bool(true)
53+
b from global:bool(true)
54+
c from global:bool(false)
55+
d from global:bool(false)
56+
e from global:
57+
Notice: Only variable references should be returned by reference in %s%eext%ereflection%etests%egh22000.php on line %d
3758
bool(false)
38-
c from global:
39-
Notice: Only variable references should be returned by reference in /home/zaaarf/dev/irl/c/php/ext/reflection/tests/gh22000.php on line 13
59+
f from global:
60+
Notice: Only variable references should be returned by reference in %s%eext%ereflection%etests%egh22000.php on line %d
4061
bool(true)

0 commit comments

Comments
 (0)