mirror of
https://github.com/php/doc-en.git
synced 2026-03-24 07:42:10 +01:00
129 lines
3.3 KiB
XML
129 lines
3.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<refentry xml:id="reflectionclass.initializelazyobject" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>ReflectionClass::initializeLazyObject</refname>
|
|
<refpurpose>Forces initialization of a lazy object</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis role="ReflectionClass">
|
|
<modifier>public</modifier> <type>object</type><methodname>ReflectionClass::initializeLazyObject</methodname>
|
|
<methodparam><type>object</type><parameter>object</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
Forces initialization of the specified <parameter>object</parameter>. This
|
|
method has no effect if the object is not lazy or has already been
|
|
initialized. Otherwise, initialization proceeds as described in the
|
|
<link linkend="language.oop5.lazy-objects.initialization-sequence">Initialization
|
|
Sequence</link>.
|
|
</simpara>
|
|
|
|
<note>
|
|
<simpara>
|
|
In most cases, calling this method is unnecessary, as lazy objects
|
|
initialize themselves automatically when their state is observed or
|
|
modified.
|
|
</simpara>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>object</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
The object to initialize.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<simpara>
|
|
If <parameter>object</parameter> is a lazy proxy, returns its real instance.
|
|
Otherwise, returns <parameter>object</parameter> itself.
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Basic usage</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class Example
|
|
{
|
|
public function __construct(public int $prop) {
|
|
}
|
|
}
|
|
|
|
$reflector = new ReflectionClass(Example::class);
|
|
|
|
$object = $reflector->newLazyGhost(function ($object) {
|
|
echo "Initializer called\n";
|
|
$object->__construct(1);
|
|
});
|
|
|
|
var_dump($object);
|
|
|
|
$reflector->initializeLazyObject($object);
|
|
|
|
var_dump($object);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
lazy ghost object(Example)#3 (0) {
|
|
["prop"]=>
|
|
uninitialized(int)
|
|
}
|
|
Initializer called
|
|
object(Example)#3 (1) {
|
|
["prop"]=>
|
|
int(1)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member><link linkend="language.oop5.lazy-objects">Lazy objects</link></member>
|
|
<member><methodname>ReflectionClass::newLazyGhost</methodname></member>
|
|
<member><methodname>ReflectionClass::markLazyObjectAsInitialized</methodname></member>
|
|
<member><methodname>ReflectionClass::isUninitializedLazyObject</methodname></member>
|
|
</simplelist>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|