1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Files
archived-php-src/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_003.phpt
Nikita Popov e219ec144e Implement typed properties
RFC: https://wiki.php.net/rfc/typed_properties_v2

This is a squash of PR #3734, which is a squash of PR #3313.

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
Co-authored-by: Joe Watkins <krakjoe@php.net>
Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2019-01-11 15:49:06 +01:00

40 lines
769 B
PHP

--TEST--
ReflectionClass::setStaticPropertyValue() - type constraints must be enforced
--FILE--
<?php
class Test {
public static $x;
public static int $y = 2;
}
$rc = new ReflectionClass('Test');
try {
$rc->setStaticPropertyValue("y", "foo");
} catch (TypeError $e) { echo $e->getMessage(), "\n"; }
var_dump(Test::$y);
$rc->setStaticPropertyValue("y", "21");
var_dump(Test::$y);
Test::$x =& Test::$y;
try {
$rc->setStaticPropertyValue("x", "foo");
} catch (TypeError $e) { echo $e->getMessage(), "\n"; }
var_dump(Test::$y);
$rc->setStaticPropertyValue("x", "42");
var_dump(Test::$y);
?>
--EXPECT--
Typed property Test::$y must be int, string used
int(2)
int(21)
Cannot assign string to reference held by property Test::$y of type int
int(21)
int(42)