[doc-en] master: property_exists: Update example to show more scenarios. (#4508)

From: Date: Wed, 02 Sep 2026 09:03:34 +0000
Subject: [doc-en] master: property_exists: Update example to show more scenarios. (#4508)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-23697@lists.php.net to get a copy of this message
Author: Russell (zimzat) Committer: GitHub (web-flow) Pusher: lacatoire Date: 2026-09-02T11:03:30+02:00 Commit: https://github.com/php/doc-en/commit/623a2701987917d7c6b78511cbda442fc17ce500 Raw diff: https://github.com/php/doc-en/commit/623a2701987917d7c6b78511cbda442fc17ce500.diff property_exists: Update example to show more scenarios. (#4508) * property_exists: Update example to show more scenarios. The main thing to highlight is that property visibility and __get and __isset is not checked. * docs(property_exists): split into two examples, keep original and add visibility/magic methods example * fix: move example description outside <example> element * Use simpara for the inline-only paragraph --------- Co-authored-by: lacatoire <la.catoire@gmail.com> Changed paths: M reference/classobj/functions/property-exists.xml Diff: diff --git a/reference/classobj/functions/property-exists.xml b/reference/classobj/functions/property-exists.xml index b8f2e54d7c6f..b4193e01dfb4 100644 --- a/reference/classobj/functions/property-exists.xml +++ b/reference/classobj/functions/property-exists.xml @@ -87,6 +87,68 @@ myClass::test(); </programlisting> </example> </para> + <simpara> + <function>property_exists</function> returns &true; regardless of property + visibility, detects dynamic properties added to instances (when the class + uses <literal>#[AllowDynamicProperties]</literal>), and ignores + <link linkend="language.oop5.overloading.members"><literal>__isset</literal></link> + and <literal>__get</literal> magic methods. + </simpara> + <para> + <example> + <title>Visibility, dynamic properties, and magic methods</title> + <programlisting role="php"> +<![CDATA[ +<?php + +#[AllowDynamicProperties] +class MyClass { + public $public; + private $private; + static protected $protectedStatic; + + // ignored by property_exists + public function __isset(string $name): bool { + return true; + } + + // ignored by property_exists + public function __get(string $name): string { + return ''; + } +} + +$instance = new MyClass(); +$instance->instanced = 'abc'; + +var_dump(property_exists($instance, 'public')); // true (public) +var_dump(property_exists($instance, 'private')); // true (visibility ignored) +var_dump(property_exists($instance, 'protectedStatic')); // true (visibility ignored) +var_dump(property_exists($instance, 'instanced')); // true (dynamic property on instance) +var_dump(property_exists($instance, 'undefined')); // false (not declared, __isset ignored) + +var_dump(property_exists(MyClass::class, 'public')); // true +var_dump(property_exists(MyClass::class, 'instanced')); // false (dynamic props not on class) +var_dump(property_exists(MyClass::class, 'undefined')); // false + +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) +bool(false) +bool(false) +]]> + </screen> + </example> + </para> </refsect1> <refsect1 role="notes">

« previous php.doc.cvs (#23697) next »