php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80686 PHP reflection bug, PHP doesn't see the PHPDoc for the 2nd property.
Submitted: 2021-01-29 16:21 UTC Modified: 2021-01-29 19:50 UTC
From: darrens at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 7.4.14 OS: Ubuntu 20.04.2
Private report: No CVE-ID: None
 [2021-01-29 16:21 UTC] darrens at gmail dot com
Description:
------------
Specific PHP Version is 7.4.3 (Default PHP version installed with Ubuntu).

PHP reflection bug, PHP doesn't see the PHPDoc for the 2nd property. I encountered this bug while using PHPStan: https://github.com/phpstan/phpstan/issues/4454 and package maintainer referenced a second related instance: https://github.com/phpstan/phpstan/issues/4445



Test script:
---------------
https://3v4l.org/oL3Ke

<?php declare(strict_types = 1);

class Client
{
    /**
     * Pass Login variable
     *
     * @var array<string, string|null>
     */
    private array $_login, $_created_ip;
}

$ref = new \ReflectionClass(Client::class);

foreach ($ref->getProperties() as $prop) {
    var_dump($prop->getDocComment());
}

Expected result:
----------------
string(84) "/**
     * Pass Login variable
     *
     * @var array<string, string|null>
     */"

Actual result:
--------------
string(84) "/**
     * Pass Login variable
     *
     * @var array<string, string|null>
     */"
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-29 19:50 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-01-29 19:50 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

https://www.php.net/manual/en/reflectionproperty.getdoccomment.php
> If multiple property declarations are preceeded by a single doc comment, the doc
> comment refers to the first property only.
 [2021-01-29 20:12 UTC] darrens at gmail dot com
Thank you for your quick response. I missed that in the documentation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 15:01:32 2024 UTC