[php-src] Issue #19224: newLazyProxy($closure) throws error on $closure result null, but can't capture it.

From: Date: Wed, 23 Jul 2025 16:47:21 +0000
Subject: [php-src] Issue #19224: newLazyProxy($closure) throws error on $closure result null, but can't capture it.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250481@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/19224 Author: procodix ### Description The following code: ```php class Test { public string $Foo = 'Bar'; } $proxy = new ReflectionClass(Test::class)->newLazyProxy(fn() => null); $proxy->Foo; <?php ``` Resulted in this output: ``` Error: Lazy proxy factory must return an instance of a class compatible with Zok\System\Test, null returned ``` But I expected instead: - allow "null" to be returned from the closure, so that its signature be like: ``function($ghost):?object`` - allow the error thrown to be captured and instead return null, and replace the proxy shell with null BTW this would could collapse ghosts and proxies to a single lazy concept, allowing to return - a previously empty shell object, now filled with - a freshly created object - null. This is important if -for example- a database lookup returned no result ``` ### PHP Version ```plain PHP 8.4 ``` ### Operating System macOS

« previous php.bugs (#250481) next »