php-src
php-src copied to clipboard
`ReflectionProperty::setValue()` does implicit conversion using strict types
Description
The following code:
<?php
declare(strict_types=1);
class Test
{
public string $property = '';
}
$test = new Test();
$refProp = new \ReflectionProperty(Test::class, 'property');
$refProp->setValue($test, 3);
var_dump($test->property);
Resulted in this output:
string(1) "3"
But I expected this output instead:
Fatal error: Uncaught TypeError: Cannot assign int to property Test::$property of type string
Link to 3v4l: https://3v4l.org/m0Te8
PHP Version
PHP >= 7.4
Operating System
Any
PHP does not enable strict_types for its own actions. https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict
thanks! I've been looking in docs about ReflectionProperty, but didn't look at strict types 👍