Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit49ac88d

Browse files
[VarExporter] Deprecate per-property lazy-initializers
1 parenta33a90a commit49ac88d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

‎components/var_exporter.rst‎

Lines changed: 15 additions & 11 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`` propertyisdefined 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 objectisactually 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 functioncomputeHash(array $data):string
225+
private functionpopulateHash(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

@@ -243,10 +247,10 @@ convert non-lazy classes to lazy ones::
243247

244248
public function __construct(array $data)
245249
{
246-
$this->hash = $this->computeHash($data);
250+
$this->populateHash($data);
247251
}
248252

249-
private functioncomputeHash(array $data):string
253+
private functionpopulateHash(array $data):void
250254
{
251255
// ...
252256
}
@@ -330,10 +334,10 @@ code::
330334
{
331335
public function __construct(array $data)
332336
{
333-
$this->hash = $this->computeHash($data);
337+
$this->populateHash($data);
334338
}
335339

336-
private functioncomputeHash(array $data):string
340+
private functionpopulateHash(array $data):void
337341
{
338342
// ...
339343
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp