You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
451 B
22 lines
451 B
<?php
|
|
|
|
require "libs/LazyObject.php";
|
|
|
|
class MyClass {
|
|
public function __construct(public int $num) {}
|
|
public function someMethod() {
|
|
return $this->num;
|
|
}
|
|
}
|
|
|
|
class Example2 {
|
|
public function hi() { echo "Hi!"; }
|
|
}
|
|
|
|
$lazy = new LazyObject();
|
|
$object = $lazy::proxy(MyClass::class, 301);
|
|
// The object is initialized only when accessed
|
|
echo $object->someMethod() . "\n";
|
|
|
|
$objectB = $lazy::proxy(Example2::class);
|
|
$objectB->hi();
|
|
|