main.php
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 (cli) (built: Jun 23 2016 23:39:14) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies