-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazy_proxy.php
More file actions
38 lines (29 loc) · 806 Bytes
/
lazy_proxy.php
File metadata and controls
38 lines (29 loc) · 806 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/*
* Copyright (C) 2024-2026 Katarzyna Krasińska
* PHP.lab - https://github.com/katheroine/php.lab
* Licensed under GPL-3.0 - see LICENSE.md
*/
class SomeClass
{
public string $someProperty;
public function __construct(string $someProperty)
{
print("Construction...\n");
$this->someProperty = $someProperty;
}
}
$someReflection = new ReflectionClass(SomeClass::class);
$someProxy = $someReflection->newLazyProxy(function (SomeClass $object) {
return new SomeClass('initialised');
});
print(
'Proxy type: ' . gettype($someProxy) . PHP_EOL
. 'Proxy class: ' . get_class($someProxy) . PHP_EOL
. PHP_EOL
);
var_dump($someProxy);
print(PHP_EOL);
print("Property reading: {$someProxy->someProperty}\n\n");
var_dump($someProxy);
print(PHP_EOL);