Skip to content

Commit 5de8d6b

Browse files
committed
Minor tweaks
1 parent d41f486 commit 5de8d6b

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

components/var_exporter.rst

+28-28
Original file line numberDiff line numberDiff line change
@@ -177,53 +177,53 @@ populated by using the special ``"\0"`` property name to define their internal v
177177
"\0" => [$inputArray],
178178
]);
179179

180-
Creating Lazy Objects on PHP ≥ 8.4
181-
----------------------------------
180+
Creating Lazy Objects
181+
---------------------
182182

183-
Since version 8.4, PHP provides support for lazy objects via the reflection API.
184-
This native API works with concrete classes. It doesn't with abstracts nor with
185-
internal ones.
183+
Lazy objects are objects instantiated empty and populated on demand. This is
184+
particularly useful when, for example, a class has properties that require
185+
heavy computation to determine their values. In such cases, you may want to
186+
trigger the computation only when the property is actually accessed. This way,
187+
the expensive processing is avoided entirely if the property is never used.
186188

187-
This components provides helpers to generate lazy objects using the decorator
188-
pattern, which works with abstract or internal classes and with interfaces::
189+
Since version 8.4, PHP provides support for lazy objects via the reflection API.
190+
This native API works with concrete classes, but not with abstract or internal ones.
191+
This component provides helpers to generate lazy objects using the decorator
192+
pattern, which also works with abstract classes, internal classes, and interfaces::
189193

190194
$proxyCode = ProxyHelper::generateLazyProxy(new \ReflectionClass(SomeInterface::class));
191-
// $proxyCode should be dumped into a file in production envs
195+
// $proxyCode should be dumped into a file in production environments
192196
eval('class ProxyDecorator'.$proxyCode);
193197

194198
$proxy = ProxyDecorator::createLazyProxy(initializer: function (): SomeInterface {
195-
// [...] Use whatever heavy logic you need here
199+
// use whatever heavy logic you need here
196200
// to compute the $dependencies of the proxied class
197201
$instance = new SomeHeavyClass(...$dependencies);
198-
// [...] Call setters, etc. if needed
202+
// call setters, etc. if needed
199203

200204
return $instance;
201205
});
202206

203207
Use this mechanism only when native lazy objects cannot be leveraged
204-
(or you'll get a deprecation notice.)
208+
(otherwise you'll get a deprecation notice).
205209

206-
Creating Lazy Objects on PHP < 8.3
207-
----------------------------------
210+
Legacy Creation of Lazy Objects
211+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208212

209-
Lazy-objects are objects instantiated empty and populated on-demand. This is
210-
particularly useful when you have for example properties in your classes that
211-
requires some heavy computation to determine their value. In this case, you
212-
may want to trigger the property's value processing only when you actually need
213-
its value. Thanks to this, the heavy computation won't be done if you never use
214-
this property. The VarExporter component is bundled with two traits helping
215-
you implement such mechanism easily in your classes.
213+
When using a PHP version earlier than 8.4, native lazy objects are not available.
214+
In these cases, the VarExporter component provides two traits that help you
215+
implement lazy-loading mechanisms in your classes.
216216

217217
.. _var-exporter_ghost-objects:
218218

219219
LazyGhostTrait
220-
~~~~~~~~~~~~~~
220+
..............
221221

222222
.. deprecated:: 7.3
223223

224-
``LazyGhostTrait`` is deprecated since Symfony 7.3; use PHP 8.4's native lazy
225-
objects instead (note that using the trait with PHP < 8.4 triggers no deprecation
226-
to help with the transition.)
224+
``LazyGhostTrait`` is deprecated since Symfony 7.3. Use PHP 8.4's native lazy
225+
objects instead. Note that using the trait with PHP versions earlier than 8.4
226+
does not trigger a deprecation, to ease the transition.
227227

228228
Ghost objects are empty objects, which see their properties populated the first
229229
time any method is called. Thanks to :class:`Symfony\\Component\\VarExporter\\LazyGhostTrait`,
@@ -303,13 +303,13 @@ of :ref:`Virtual Proxies <var-exporter_virtual-proxies>`.
303303
.. _var-exporter_virtual-proxies:
304304

305305
LazyProxyTrait
306-
~~~~~~~~~~~~~~
306+
..............
307307

308308
.. deprecated:: 7.3
309309

310-
``LazyProxyTrait`` is deprecated since Symfony 7.3; use PHP 8.4's native lazy
311-
objects instead (note that using the trait with PHP < 8.4 triggers no deprecation
312-
to help with the transition.)
310+
``LazyProxyTrait`` is deprecated since Symfony 7.3. Use PHP 8.4's native lazy
311+
objects instead. Note that using the trait with PHP versions earlier than 8.4
312+
does not trigger a deprecation, to ease the transition.
313313

314314
The purpose of virtual proxies in the same one as
315315
:ref:`ghost objects <var-exporter_ghost-objects>`, but their internal behavior is

0 commit comments

Comments
 (0)