Whats new in PHP 8.4
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.
php84/LazyObject.php

21 lines
447 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!"; }
}
$object = new LazyObject()->proxy(MyClass::class, 301);
// The object is initialized only when accessed
echo $object->someMethod() . "\n";
$objectB = new LazyObject()->proxy(Example2::class);
$objectB->hi();