diff --git a/Zend/tests/bug78868.phpt b/Zend/tests/bug78868.phpt index 7502662c9e7..658b527abd8 100644 --- a/Zend/tests/bug78868.phpt +++ b/Zend/tests/bug78868.phpt @@ -25,7 +25,7 @@ spl_autoload_register('main_autoload'); $classA = new ReflectionClass("A"); $props = $classA->getProperties(); -$props[0]->setValue(2); //causes constant resolving, which runs autoload, all with EG(fake_scope) == "A" +$props[0]->setValue(null, 2); //causes constant resolving, which runs autoload, all with EG(fake_scope) == "A" echo "OK\n"; ?> diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index bcd506a3500..a6aa6931be1 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5720,6 +5720,22 @@ ZEND_METHOD(ReflectionProperty, setValue) if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &tmp, &value) == FAILURE) { RETURN_THROWS(); } + + if (Z_TYPE_P(tmp) != IS_NULL && Z_TYPE_P(tmp) != IS_OBJECT) { + zend_string *method_name = get_active_function_or_method_name(); + zend_error(E_DEPRECATED, "Calling %s() with a 1st argument which is not null or an object is deprecated", ZSTR_VAL(method_name)); + zend_string_release(method_name); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); + } + } + } else { + zend_string *method_name = get_active_function_or_method_name(); + zend_error(E_DEPRECATED, "Calling %s() with a single argument is deprecated", ZSTR_VAL(method_name)); + zend_string_release(method_name); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); + } } zend_update_static_property_ex(intern->ce, ref->unmangled_name, value); diff --git a/ext/reflection/tests/ReflectionProperty_setAccessible.phpt b/ext/reflection/tests/ReflectionProperty_setAccessible.phpt index 80ed15d6903..4e12af87916 100644 --- a/ext/reflection/tests/ReflectionProperty_setAccessible.phpt +++ b/ext/reflection/tests/ReflectionProperty_setAccessible.phpt @@ -23,9 +23,9 @@ var_dump($private->getValue($a)); var_dump($privateStatic->getValue()); $protected->setValue($a, 'e'); -$protectedStatic->setValue('f'); +$protectedStatic->setValue(null, 'f'); $private->setValue($a, 'g'); -$privateStatic->setValue('h'); +$privateStatic->setValue(null, 'h'); var_dump($protected->getValue($a)); var_dump($protectedStatic->getValue()); @@ -45,7 +45,7 @@ var_dump($privateStatic->getValue()); $protected->setValue($a, 'i'); $protectedStatic->setValue('j'); $private->setValue($a, 'k'); -$privateStatic->setValue('l'); +$privateStatic->setValue(null, 'l'); var_dump($protected->getValue($a)); var_dump($protectedStatic->getValue()); @@ -63,7 +63,7 @@ var_dump($protectedStatic->getValue()); var_dump($private->getValue($b)); $protected->setValue($b, 'e'); -$protectedStatic->setValue('f'); +$protectedStatic->setValue(null, 'f'); $private->setValue($b, 'g'); var_dump($protected->getValue($b)); @@ -79,14 +79,14 @@ var_dump($protectedStatic->getValue()); var_dump($private->getValue($b)); $protected->setValue($b, 'h'); -$protectedStatic->setValue('i'); +$protectedStatic->setValue(null, 'i'); $private->setValue($b, 'j'); var_dump($protected->getValue($b)); var_dump($protectedStatic->getValue()); var_dump($private->getValue($b)); ?> ---EXPECT-- +--EXPECTF-- string(1) "a" string(1) "b" string(1) "c" @@ -99,6 +99,8 @@ string(1) "e" string(1) "f" string(1) "g" string(1) "h" + +Deprecated: Calling ReflectionProperty::setValue() with a single argument is deprecated in %s on line %d string(1) "i" string(1) "j" string(1) "k" diff --git a/ext/reflection/tests/ReflectionProperty_typed_static.phpt b/ext/reflection/tests/ReflectionProperty_typed_static.phpt index eaf42096446..032f9b18ef3 100644 --- a/ext/reflection/tests/ReflectionProperty_typed_static.phpt +++ b/ext/reflection/tests/ReflectionProperty_typed_static.phpt @@ -19,11 +19,11 @@ try { echo $e->getMessage(), "\n"; } -$rp->setValue("24"); +$rp->setValue(null, "24"); var_dump($rp->getValue()); try { - $rp->setValue("foo"); + $rp->setValue(null, "foo"); } catch (TypeError $e) { echo $e->getMessage(), "\n"; } @@ -33,7 +33,7 @@ Test::$z =& Test::$y; $rp = new ReflectionProperty('Test', 'z'); try { - $rp->setValue("foo"); + $rp->setValue(null, "foo"); } catch (TypeError $e) { echo $e->getMessage(), "\n"; } diff --git a/ext/reflection/tests/bug30146.phpt b/ext/reflection/tests/bug30146.phpt index d2e54324a72..3b4ca905738 100644 --- a/ext/reflection/tests/bug30146.phpt +++ b/ext/reflection/tests/bug30146.phpt @@ -15,7 +15,9 @@ var_dump($r->getValue()); $r->setValue(3); var_dump($r->getValue()); ?> ---EXPECT-- +--EXPECTF-- int(1) int(2) + +Deprecated: Calling ReflectionProperty::setValue() with a single argument is deprecated in %s on line %d int(3) diff --git a/ext/reflection/tests/bug71018.phpt b/ext/reflection/tests/bug71018.phpt index 00baa31d3c2..cbbb7325e9f 100644 --- a/ext/reflection/tests/bug71018.phpt +++ b/ext/reflection/tests/bug71018.phpt @@ -28,6 +28,17 @@ $Prop2->setValue(\T2::class, 'hello'); var_dump("T2::self = " . T2::getDataBySelf()); var_dump("T2::static = " . T2::getDataByStatic()); +set_error_handler(function ($severity, $message, $file, $line) { + throw new Exception($message); +}); +try { + $Prop2->setValue(\T2::class, 'hi'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +var_dump("T2::self = " . T2::getDataByStatic()); + // #2 // prints: hello, hello in both PHP5 and PHP7 - OK T1::$data = "world"; @@ -36,8 +47,13 @@ T2::$data = 'hello'; var_dump("T2::self = " . T2::getDataBySelf()); var_dump("T2::static = " . T2::getDataByStatic()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling ReflectionProperty::setValue() with a 1st argument which is not null or an object is deprecated in %s on line %d + +Deprecated: Calling ReflectionProperty::setValue() with a 1st argument which is not null or an object is deprecated in %s on line %d string(16) "T2::self = hello" string(18) "T2::static = hello" +Calling ReflectionProperty::setValue() with a 1st argument which is not null or an object is deprecated +string(16) "T2::self = hello" string(16) "T2::self = hello" string(18) "T2::static = hello" diff --git a/ext/reflection/tests/internal_static_property.phpt b/ext/reflection/tests/internal_static_property.phpt index bf4294d8dec..5b5e1c353c5 100644 --- a/ext/reflection/tests/internal_static_property.phpt +++ b/ext/reflection/tests/internal_static_property.phpt @@ -6,7 +6,7 @@ zend_test setValue(42); +$rp->setValue(new _ZendTestClass(), 42); var_dump($rp->getValue()); ?>