main
Robert 8 months ago
parent ae3973a5d0
commit ea048ab9e7
  1. 5
      LazyObject.php
  2. 2
      libs/LazyObject.php

@ -13,9 +13,10 @@ class Example2 {
public function hi() { echo "Hi!"; }
}
$object = new LazyObject()->proxy(MyClass::class, 301);
$lazy = new LazyObject();
$object = $lazy::proxy(MyClass::class, 301);
// The object is initialized only when accessed
echo $object->someMethod() . "\n";
$objectB = new LazyObject()->proxy(Example2::class);
$objectB = $lazy::proxy(Example2::class);
$objectB->hi();

@ -1,6 +1,6 @@
<?php
class LazyObject {
public function proxy(string $className, mixed $c = null) {
public static function proxy(string $className, mixed $c = null) {
if (!class_exists($className, true)) {
throw new InvalidArgumentException("Class {$className} does not exist");
}

Loading…
Cancel
Save