3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected $var; public function setVar(string $var) { $this->var = $var; } } $reflection = new ReflectionClass('A'); $property = $reflection->getProperty('var'); $property->setAccessible(true); $classA = new A(); $classA->setVar('howdy, partner'); var_dump($property->getValue($classA));
Output for 8.5.1 - 8.5.3
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /in/6uS1Y on line 13 string(14) "howdy, partner"
Output for 8.5.0
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in /in/6uS1Y on line 13 string(14) "howdy, partner"
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18
string(14) "howdy, partner"

preferences:
98.98 ms | 1490 KiB | 4 Q