mirror of
https://github.com/php/php-src.git
synced 2024-09-25 03:47:26 +00:00
Merge branch 'PHP-7.0'
This commit is contained in:
commit
d92c75f923
@ -5448,31 +5448,16 @@ ZEND_METHOD(reflection_property, setValue)
|
|||||||
}
|
}
|
||||||
variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset];
|
variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset];
|
||||||
if (variable_ptr != value) {
|
if (variable_ptr != value) {
|
||||||
if (Z_ISREF_P(variable_ptr)) {
|
zval garbage;
|
||||||
zval garbage;
|
|
||||||
|
|
||||||
ZVAL_COPY_VALUE(&garbage, variable_ptr); /* old value should be destroyed */
|
ZVAL_DEREF(variable_ptr);
|
||||||
|
ZVAL_DEREF(value);
|
||||||
|
|
||||||
/* To check: can't *variable_ptr be some system variable like error_zval here? */
|
ZVAL_COPY_VALUE(&garbage, variable_ptr);
|
||||||
ZVAL_COPY_VALUE(variable_ptr, value);
|
|
||||||
if (Z_REFCOUNTED_P(value) && Z_REFCOUNT_P(value) > 0) {
|
|
||||||
zval_copy_ctor(variable_ptr);
|
|
||||||
}
|
|
||||||
zval_dtor(&garbage);
|
|
||||||
} else {
|
|
||||||
zval garbage;
|
|
||||||
|
|
||||||
ZVAL_COPY_VALUE(&garbage, variable_ptr);
|
ZVAL_COPY(variable_ptr, value);
|
||||||
/* if we assign referenced variable, we should separate it */
|
|
||||||
if (Z_REFCOUNTED_P(value)) {
|
zval_ptr_dtor(&garbage);
|
||||||
Z_ADDREF_P(value);
|
|
||||||
}
|
|
||||||
if (Z_ISREF_P(value)) {
|
|
||||||
SEPARATE_ZVAL(value);
|
|
||||||
}
|
|
||||||
ZVAL_COPY_VALUE(variable_ptr, value);
|
|
||||||
zval_ptr_dtor(&garbage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char *class_name, *prop_name;
|
const char *class_name, *prop_name;
|
||||||
|
@ -132,7 +132,7 @@ string(44) "Cannot access non-public member B::protected"
|
|||||||
string(50) "Cannot access non-public member B::protectedStatic"
|
string(50) "Cannot access non-public member B::protectedStatic"
|
||||||
string(42) "Cannot access non-public member A::private"
|
string(42) "Cannot access non-public member A::private"
|
||||||
string(1) "a"
|
string(1) "a"
|
||||||
string(1) "b"
|
string(1) "f"
|
||||||
string(1) "c"
|
string(1) "c"
|
||||||
string(1) "e"
|
string(1) "e"
|
||||||
string(1) "f"
|
string(1) "f"
|
||||||
|
43
ext/reflection/tests/bug71018.phpt
Normal file
43
ext/reflection/tests/bug71018.phpt
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
--TEST--
|
||||||
|
Bug #71018 (ReflectionProperty::setValue() behavior changed)
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
class T1 {
|
||||||
|
public static $data;
|
||||||
|
|
||||||
|
public static function getDataBySelf()
|
||||||
|
{
|
||||||
|
return self::$data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataByStatic()
|
||||||
|
{
|
||||||
|
return static::$data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class T2 extends T1 {}
|
||||||
|
|
||||||
|
$Prop1 = new ReflectionProperty(T1::class, 'data');
|
||||||
|
$Prop2 = new ReflectionProperty(T2::class, 'data');
|
||||||
|
|
||||||
|
// #1
|
||||||
|
// prints: hello, hello in PHP5, but world, hello in PHP7 - not OK
|
||||||
|
$Prop1->setValue(\T1::class, "world");
|
||||||
|
$Prop2->setValue(\T2::class, 'hello');
|
||||||
|
var_dump("T2::self = " . T2::getDataBySelf());
|
||||||
|
var_dump("T2::static = " . T2::getDataByStatic());
|
||||||
|
|
||||||
|
// #2
|
||||||
|
// prints: hello, hello in both PHP5 and PHP7 - OK
|
||||||
|
T1::$data = "world";
|
||||||
|
T2::$data = 'hello';
|
||||||
|
|
||||||
|
var_dump("T2::self = " . T2::getDataBySelf());
|
||||||
|
var_dump("T2::static = " . T2::getDataByStatic());
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(16) "T2::self = hello"
|
||||||
|
string(18) "T2::static = hello"
|
||||||
|
string(16) "T2::self = hello"
|
||||||
|
string(18) "T2::static = hello"
|
Loading…
Reference in New Issue
Block a user