Skip to content

Commit bcada03

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79683
2 parents 797c1c5 + 2447fd9 commit bcada03

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Zend/zend_object_handlers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,9 +1800,12 @@ ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj,
18001800
zend_class_entry *ce = readobj->ce;
18011801
if (ce->__tostring) {
18021802
zval retval;
1803+
zend_class_entry *fake_scope = EG(fake_scope);
1804+
EG(fake_scope) = NULL;
18031805
GC_ADDREF(readobj);
18041806
zend_call_method_with_0_params(readobj, ce, &ce->__tostring, "__tostring", &retval);
18051807
zend_object_release(readobj);
1808+
EG(fake_scope) = fake_scope;
18061809
if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
18071810
ZVAL_COPY_VALUE(writeobj, &retval);
18081811
return SUCCESS;

ext/reflection/tests/bug79683.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #79683: Fake reflection scope affects __toString()
3+
--FILE--
4+
<?php
5+
6+
class A
7+
{
8+
private string $prop1 = '123';
9+
10+
public function __toString()
11+
{
12+
return $this->prop1;
13+
}
14+
}
15+
16+
class B
17+
{
18+
private string $prop2;
19+
}
20+
21+
$b = new B();
22+
23+
$reflector = new ReflectionClass($b);
24+
$property = $reflector->getProperty('prop2');
25+
$property->setAccessible(true);
26+
$property->setValue($b, new A());
27+
28+
var_dump($b);
29+
30+
?>
31+
--EXPECT--
32+
object(B)#1 (1) {
33+
["prop2":"B":private]=>
34+
string(3) "123"
35+
}

0 commit comments

Comments
 (0)