mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Document ReflectionProperty::getDefaultValue and ::hasDefaultValue
Patch provided by Benjamin Eberlei <kontakt@beberlei.de>. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@351090 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
6efef65e17
commit
d960106581
3 changed files with 202 additions and 0 deletions
100
reference/reflection/reflectionproperty/getdefaultvalue.xml
Normal file
100
reference/reflection/reflectionproperty/getdefaultvalue.xml
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<refentry xml:id="reflectionproperty.getdefaultvalue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>ReflectionProperty::getDefaultValue</refname>
|
||||
<refpurpose>Returns the default value declared for a property</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>mixed</type><methodname>ReflectionProperty::getDefaultValue</methodname>
|
||||
<void />
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
Gets the implicit or explicitly declared default value for a property.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
The default value if the property has any default value (including &null;).
|
||||
If there is no default value, then &null; is returned. It is not possible to differentiate
|
||||
between a &null; default value and an unitialized typed property.
|
||||
Use <methodname>ReflectionClass::hasDefaultValue</methodname> to detect the difference.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title><methodname>ReflectionClass::getDefaultValue</methodname> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class Foo {
|
||||
public $bar = 1;
|
||||
public ?int $baz;
|
||||
public int $boing = 0;
|
||||
}
|
||||
|
||||
$ro = new ReflectionClass(Foo::class);
|
||||
var_dump($ro->getProperty('bar')->getDefaultValue());
|
||||
var_dump($ro->getProperty('baz')->getDefaultValue());
|
||||
var_dump($ro->getProperty('boing')->getDefaultValue());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
int(1)
|
||||
NULL
|
||||
int(0)
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<para>
|
||||
<simplelist>
|
||||
<member><methodname>ReflectionProperty::hasDefaultValue</methodname></member>
|
||||
</simplelist>
|
||||
</para>
|
||||
</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
|
||||
-->
|
||||
|
100
reference/reflection/reflectionproperty/hasdefaultvalue.xml
Normal file
100
reference/reflection/reflectionproperty/hasdefaultvalue.xml
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<refentry xml:id="reflectionproperty.hasdefaultvalue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>ReflectionProperty::hasDefaultValue</refname>
|
||||
<refpurpose>Checks if property has a default value declared</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
&reftitle.description;
|
||||
<methodsynopsis>
|
||||
<modifier>public</modifier> <type>bool</type><methodname>ReflectionProperty::hasDefaultValue</methodname>
|
||||
<void />
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
Checks whether the property was declared with a default value, including an implicit
|
||||
&null; default value. Only returns &false; for typed properties without default value (or
|
||||
dynamic properties).
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
&reftitle.parameters;
|
||||
&no.function.parameters;
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
If the property has any default value (including &null;) &true; is returned;
|
||||
if the property is typed without a default value declared or is a dynamic property, &false; is returned.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title><methodname>ReflectionClass::hasDefaultValue</methodname> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class Foo {
|
||||
public $bar;
|
||||
public ?int $baz;
|
||||
public int $boing;
|
||||
}
|
||||
|
||||
$ro = new ReflectionClass(Foo::class);
|
||||
var_dump($ro->getProperty('bar')->hasDefaultValue());
|
||||
var_dump($ro->getProperty('baz')->hasDefaultValue());
|
||||
var_dump($ro->getProperty('boing')->hasDefaultValue());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
bool(true)
|
||||
bool(false)
|
||||
bool(false)
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<para>
|
||||
<simplelist>
|
||||
<member><methodname>ReflectionProperty::getDefaultValue</methodname></member>
|
||||
</simplelist>
|
||||
</para>
|
||||
</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
|
||||
-->
|
||||
|
|
@ -286,6 +286,8 @@
|
|||
<function name="reflectionproperty::gettype" from="PHP 7 >= 7.4.0"/>
|
||||
<function name="reflectionproperty::hastype" from="PHP 7 >= 7.4.0"/>
|
||||
<function name="reflectionproperty::isinitialized" from="PHP 7 >= 7.4.0"/>
|
||||
<function name="reflectionproperty::getdefaultvalue" from="PHP 8"/>
|
||||
<function name="reflectionproperty::hasdefaultvalue" from="PHP 8"/>
|
||||
|
||||
<function name="reflectionextension" from="PHP 5, PHP 7"/>
|
||||
<function name="reflectionextension::__clone" from="PHP 5, PHP 7"/>
|
||||
|
|
Loading…
Reference in a new issue