Last active
June 15, 2023 14:43
-
-
Save Nayjest/8972170 to your computer and use it in GitHub Desktop.
PHP Wrapper class for accessing protected/private members outside class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FullAccessWrapper | |
{ | |
protected $_self; | |
protected $_refl; | |
public function __construct($self) | |
{ | |
$this->_self = $self; | |
$this->_refl = new ReflectionObject($self); | |
} | |
public function __call($method, $args) | |
{ | |
$mrefl = $this->_refl->getMethod($method); | |
$mrefl->setAccessible(true); | |
return $mrefl->invokeArgs($this->_self, $args); | |
} | |
public function __set($name, $value) | |
{ | |
$prefl = $this->_refl->getProperty($name); | |
$prefl->setAccessible(true); | |
$prefl->setValue($this->_self, $value); | |
} | |
public function __get($name) | |
{ | |
$prefl = $this->_refl->getProperty($name); | |
$prefl->setAccessible(true); | |
return $prefl->getValue($this->_self); | |
} | |
public function __isset($name) | |
{ | |
$value = $this->__get($name); | |
return isset($value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment