Skip to content

Commit 74945cf

Browse files
[VarExporter] Deprecate per-property lazy-initializers
1 parent 5d6f5ca commit 74945cf

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

components/var_exporter.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ LazyGhostTrait
199199

200200
Ghost objects are empty objects, which see their properties populated the first
201201
time any method is called. Thanks to :class:`Symfony\\Component\\VarExporter\\LazyGhostTrait`,
202-
the implementation of the lazy mechanism is eased. In the following example, the
203-
``$hash`` property is defined as lazy. Also, the ``MyLazyObject::computeHash()``
204-
method should be called only when ``$hash``'s value need to be known::
202+
the implementation of the lazy mechanism is eased. The ``MyLazyObject::populateHash()``
203+
method will be called only when the object is actually used and needs to be
204+
initialized::
205205

206206
namespace App\Hash;
207207

@@ -219,17 +219,21 @@ method should be called only when ``$hash``'s value need to be known::
219219

220220
public function __construct()
221221
{
222-
self::createLazyGhost(initializer: [
223-
'hash' => $this->computeHash(...),
224-
], instance: $this);
222+
self::createLazyGhost(initializer: $this->populateHash(...), instance: $this);
225223
}
226224

227-
private function computeHash(array $data): string
225+
private function populateHash(array $data): void
228226
{
229227
// Compute $this->hash value with the passed data
230228
}
231229
}
232230

231+
.. deprecated:: 6.4
232+
233+
Using an array of closure for property-based initialization in the
234+
``createLazyGhost()`` method is deprecated since Symfony 6.4. Pass
235+
a single closure that initializes the whole object instead.
236+
233237
:class:`Symfony\\Component\\VarExporter\\LazyGhostTrait` also allows to
234238
convert non-lazy classes to lazy ones::
235239

0 commit comments

Comments
 (0)