@nguyenvanduocit/

reflectAccessPrivateProperty

PHP (Legacy)

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9494384177068311","path":"main.php","file":{"path":"main.php","content":{"asEncoding":{"base64":"Y2xhc3MgQ2FyewogICAgcHJpdmF0ZSAkcGVvcGxlID0gYXJyYXkoKTsKICAgIHByaXZhdGUgJGNhcGFjaXR5OwoKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkY2FwYWNpdHkpIHsKICAgICAgJHRoaXMtPmNhcGFjaXR5ID0gJGNhcGFjaXR5OwogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBhZGRQZXJzb24oJG5hbWUpIHsKICAgICAgICBpZihjb3VudCgkdGhpcy0+cGVvcGxlKSA+PSAkdGhpcy0+Y2FwYWNpdHkpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEV4Y2VwdGlvbigiQ2FyIGlzIGFscmVhZHkgYXQgY2FwYWNpdHkiKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAkdGhpcy0+cGVvcGxlW10gPSAkbmFtZTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRDYXBhY2l0eSgpIHsKICAgICAgcmV0dXJuICR0aGlzLT5jYXBhY2l0eTsKICAgIH0KfQoKJGNhciA9IG5ldyBDYXIoMTApOwokY2FyLT5hZGRQZXJzb24oIk1lIik7CiRyZWZsZWN0UGVvcGxlUHJvcGVydHkgPSBuZXcgUmVmbGVjdGlvblByb3BlcnR5KCRjYXIsICdwZW9wbGUnKTsKJHJlZmxlY3RQZW9wbGVQcm9wZXJ0eS0+c2V0QWNjZXNzaWJsZSh0cnVlKTsKdmFyX2R1bXAoJHJlZmxlY3RQZW9wbGVQcm9wZXJ0eS0+Z2V0VmFsdWUoJGNhcikpOw=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Car{
    private $people = array();
    private $capacity;

    public function __construct($capacity) {
      $this->capacity = $capacity;
    }

    public function addPerson($name) {
        if(count($this->people) >= $this->capacity) {
            throw new Exception("Car is already at capacity");
        } else {
            $this->people[] = $name;
        }
    }
    
    public function getCapacity() {
      return $this->capacity;
    }
}

$car = new Car(10);
$car->addPerson("Me");
$reflectPeopleProperty = new ReflectionProperty($car, 'people');
$reflectPeopleProperty->setAccessible(true);
var_dump($reflectPeopleProperty->getValue($car));
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7