[doc-en] master: Clarify actual target returned by ReflectionAttribute::getTarget (#6145)

From: Date: Wed, 25 Nov 2026 05:37:51 +0000
Subject: [doc-en] master: Clarify actual target returned by ReflectionAttribute::getTarget (#6145)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-24015@lists.php.net to get a copy of this message
Author: Malek Kadri (malekkadri) Committer: GitHub (web-flow) Pusher: lacatoire Date: 2026-11-25T06:37:48+01:00 Commit: https://github.com/php/doc-en/commit/bcda69de512ca685721e09e8b8dc634a00d8b238 Raw diff: https://github.com/php/doc-en/commit/bcda69de512ca685721e09e8b8dc634a00d8b238.diff Clarify actual target returned by ReflectionAttribute::getTarget (#6145) Changed paths: M reference/reflection/reflectionattribute/gettarget.xml Diff: diff --git a/reference/reflection/reflectionattribute/gettarget.xml b/reference/reflection/reflectionattribute/gettarget.xml index fa31abf588a9..b0335f8b56bb 100644 --- a/reference/reflection/reflectionattribute/gettarget.xml +++ b/reference/reflection/reflectionattribute/gettarget.xml @@ -3,7 +3,7 @@ <refentry xml:id="reflectionattribute.gettarget" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>ReflectionAttribute::getTarget</refname> - <refpurpose>Returns the target of the attribute as bitmask</refpurpose> + <refpurpose>Returns the target on which the attribute is declared</refpurpose> </refnamediv> <refsect1 role="description"> @@ -12,9 +12,10 @@ <modifier>public</modifier> <type>int</type><methodname>ReflectionAttribute::getTarget</methodname> <void/> </methodsynopsis> - <para> - Gets target of the attribute as bitmask. - </para> + <simpara> + Returns the kind of declaration to which this attribute is applied. + This is distinct from the set of targets permitted by the attribute class. + </simpara> </refsect1> @@ -25,10 +26,52 @@ <refsect1 role="returnvalues"> &reftitle.returnvalues; - <para> - Gets target of the attribute as bitmask of - <link linkend="attribute.constants"><constant>Attribute::TARGET_*</constant> constants</link>. - </para> + <simpara> + Returns the corresponding + <link linkend="attribute.constants"><constant>Attribute::TARGET_*</constant> constant</link>. + The permitted targets of the attribute class can instead be obtained from + the <property>flags</property> property of its <classname>Attribute</classname> + instance. + </simpara> + </refsect1> + + <refsect1 role="examples"> + &reftitle.examples; + <example> + <title>Distinguishing actual and permitted attribute targets</title> + <programlisting role="php"> +<![CDATA[ +<?php +#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] +class Marker {} + +#[Marker] +class Example +{ + #[Marker] + public $value; +} + +$class = new ReflectionClass(Example::class); +$property = new ReflectionProperty(Example::class, 'value'); + +var_dump($class->getAttributes(Marker::class)[0]->getTarget()); +var_dump($property->getAttributes(Marker::class)[0]->getTarget()); + +$definition = new ReflectionClass(Marker::class); +var_dump($definition->getAttributes(Attribute::class)[0]->newInstance()->flags); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +int(1) +int(8) +int(9) +]]> + </screen> + </example> </refsect1> </refentry>

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