反射(后期绑定)

<?php

class MacBook {
    public $year = 0;
    public $version = "";

    function __construct(int $year, string $version) {
        $this->year = $year;
        $this->version = $version;
    }

    function showInfo() {
        echo "year = $this->year, version = $this->version";
    }
}

//show methods
$methods = get_class_methods("MacBook");
foreach ($methods as $method) {
    echo $method, "\n";
}

//show properties
$ref = new ReflectionClass('MacBook');
print_r($ref->getProperties(ReflectionProperty::IS_PUBLIC));