com doc/ja: Extend ReflectionProperty::hasDefaultValue() example: reference/reflection/reflectionproperty/hasdefaultvalue.xml

From: Date: Fri, 08 Jan 2021 01:10:56 +0000
Subject: com doc/ja: Extend ReflectionProperty::hasDefaultValue() example: reference/reflection/reflectionproperty/hasdefaultvalue.xml
Groups: php.doc.ja 
Request: Send a blank email to doc-ja+get-6045@lists.php.net to get a copy of this message
Commit: f6dde886634a8320297042b7d684d56cfa9ce269 Author: Yoshinari Takaoka <mumumu@mumumu.org> Fri, 8 Jan 2021 10:10:56 +0900 Parents: d0aead84b54d331a5bb19a115e060db1fea6640f Branches: master Link: http://git.php.net/?p=doc/ja.git;a=commitdiff;h=f6dde886634a8320297042b7d684d56cfa9ce269 Log: Extend ReflectionProperty::hasDefaultValue() example Closes GH-295. Changed paths: M reference/reflection/reflectionproperty/hasdefaultvalue.xml Diff: diff --git a/reference/reflection/reflectionproperty/hasdefaultvalue.xml b/reference/reflection/reflectionproperty/hasdefaultvalue.xml index ed3d804e03..29a88994ac 100644 --- a/reference/reflection/reflectionproperty/hasdefaultvalue.xml +++ b/reference/reflection/reflectionproperty/hasdefaultvalue.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> -<!-- EN-Revision: d960106581fd3cc7010269c01a97753fe470d5d5 Maintainer: mumumu Status: ready --> +<!-- EN-Revision: a2afb71b63c1ca0dc2b5c5d1cb35d55d4e583aec Maintainer: mumumu Status: ready --> <refentry xml:id="reflectionproperty.hasdefaultvalue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> @@ -45,13 +45,22 @@ class Foo { public $bar; public ?int $baz; + public ?int $foo = null; public int $boing; + + public function __construct() + { + $this->ping = ''; + } } -$ro = new ReflectionClass(Foo::class); +$ro = new ReflectionObject(new Foo()); var_dump($ro->getProperty('bar')->hasDefaultValue()); var_dump($ro->getProperty('baz')->hasDefaultValue()); +var_dump($ro->getProperty('foo')->hasDefaultValue()); var_dump($ro->getProperty('boing')->hasDefaultValue()); +var_dump($ro->getProperty('ping')->hasDefaultValue()); // 動的なプロパティ +var_dump($ro->getProperty('pong')->hasDefaultValue()); // 未定義のプロパティ ?> ]]> </programlisting> @@ -60,7 +69,11 @@ var_dump($ro->getProperty('boing')->hasDefaultValue()); <![CDATA[ bool(true) bool(false) +bool(true) +bool(false) bool(false) + +Fatal error: Uncaught ReflectionException: Property Foo::$pong does not exist in example.php ]]> </screen> </example>

« previous php.doc.ja (#6045) next »