[PHP-NOTES] note 130573 added to language.attributes.overview

[email protected] ("[email protected]") Fri, 12 Dec 2025 20:04:37 +0000
Newsgroups php.notes
Message-ID <[email protected]>
It is possible to use self:: keyword in class-level attribute to reference current class, although it is actually placed "outside" class definition. Private constants also are visible. For example:

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/{id}',
            normalizationContext: ['groups' => self::NORMALIZATION_GROUPS],
        ),
    ]
)]
#[ORM\Entity]
class MyEntity
{
    private const array NORMALIZATION_GROUPS = ['groups'];
    ...
}
----
Server IP: 206.189.2.9
Probable Submitter: 195.149.108.41
----
Manual Page -- https://php.net/manual/en/language.attributes.overview.php
Edit        -- https://main.php.net/note/edit/130573
Del: integrated  -- https://main.php.net/note/delete/130573/integrated
Del: useless     -- https://main.php.net/note/delete/130573/useless
Del: bad code    -- https://main.php.net/note/delete/130573/bad+code
Del: spam        -- https://main.php.net/note/delete/130573/spam
Del: non-english -- https://main.php.net/note/delete/130573/non-english
Del: in docs     -- https://main.php.net/note/delete/130573/in+docs
Del: other reasons-- https://main.php.net/note/delete/130573
Reject      -- https://main.php.net/note/reject/130573
Search      -- https://main.php.net/manage/user-notes.php