fork download
  1. <?php
  2.  
  3. class Test {
  4. protected $var = 5;
  5. public function getVar() {
  6. echo $this->var, PHP_EOL;
  7. }
  8. }
  9.  
  10. $obj = new Test;
  11. $obj->getVar();
  12.  
  13. $refObj = new ReflectionObject( $obj );
  14. $refProp = $refObj->getProperty( 'var' );
  15. $refProp->setAccessible( true );
  16. $refProp->setValue( $obj, 555 );
  17.  
  18. $obj->getVar();
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
5
555