php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81269 getDocComment is not working correctly
Submitted: 2021-07-16 21:02 UTC Modified: 2021-08-04 09:45 UTC
From: popov654 at yandex dot ru Assigned:
Status: Open Package: Reflection related
PHP Version: 8.0.8 OS: Windows 7 x64 Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: popov654 at yandex dot ru
New email:
PHP Version: OS:

 

 [2021-07-16 21:02 UTC] popov654 at yandex dot ru
Description:
------------
If PHP is configured as an Apache module, the returned value is an empty string.

However, if you remove the space in the second line ("Thetest"), the output is correct. If you replace the space with an underscore ("_"), it still fails.

If PHP is run through the command line, the output is correct.

Also on Ubuntu 20.10 with latest Apache and PHP 8.0.8 the result is correct. So I guess it is somehow related with the Apache module for Windows.

Test script:
---------------
<?php

/**
* The test
*
* @param  foo bar
* @return baz
*/
class TestClass {

}

$class = new ReflectionClass('TestClass');

print_r($class);
echo $class->getDocComment();

?>

Expected result:
----------------
/**
* The test
*
* @param  foo bar
* @return baz
*/


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-16 21:07 UTC] popov654 at yandex dot ru
Version of Apache on Windows is 2.4.48 x64, it is also the latest one.
 [2021-07-16 21:13 UTC] requinix@php.net
-Package: Doc Build problem +Package: *General Issues
 [2021-07-16 21:13 UTC] requinix@php.net
What PHP extensions do you have enabled through Apache? Especially interested in anything that caches or "optimizes" code.
 [2021-07-16 21:13 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2021-07-17 12:51 UTC] popov654 at yandex dot ru
-Status: Feedback +Status: Open
 [2021-07-17 12:51 UTC] popov654 at yandex dot ru
extension=curl
extension=mbstring
extension=exif
extension=mysqli
extension=openssl
extension=pdo_mysql

zend_extension=opcache

Just this set. It is also the same as in 7.2 and 7.4
 [2021-07-18 11:25 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: *General Issues +Package: Reflection related -Assigned To: +Assigned To: cmb
 [2021-07-18 11:25 UTC] cmb@php.net
I cannot reproduce the reported behavior.

Does this also happen when OPcache is disabled?  Does
::getDocComment() really return an empty string, or maybe false
(use var_dump() instead of echo).  Does the OPcache error log (you
may need to set opcache.error_log and should set
opcache.log_verbosity_level=4) give any hints?
 [2021-07-18 23:45 UTC] popov654 at yandex dot ru
-Status: Feedback +Status: Assigned
 [2021-07-18 23:45 UTC] popov654 at yandex dot ru
OK, here is some more testing.

1. It is in fact bool(false) as you said
2. I enabled opcache log with level 4, and here is the output:

Mon Jul 19 02:39:30 2021 (9636): Message Cached script 'D:\xmessenger\bug.php'
Mon Jul 19 02:39:30 2021 (9636): Message Added key 'D:/xmessenger/bug.php'

No errors as you see.

3. Without opcache enabled it is really behaving correctly.


But still I consider this to be a bug. Have you tested with opcache extension on yourself? What is your Windows version where you test?

I really need opcache for better performance on versions PHP from 5.4 and newer (though my PC is not as terrible, the HDD disk performance is too bad even for lightweight PHP applications on PHP versions 5.4+).

Btw, I can check it on Win 10 x64 with latest updates if you want.
 [2021-07-19 00:21 UTC] popov654 at yandex dot ru
Ah, I got it. That was my fault with wrong configuration of opcache. I set save_comments to 0, that was the reason of stripping this out.

But the behavior of that option has changed since 7.4 anyway (it ignored PHPdoc before?). Also I don't understand why the comment is not stripped when the first line of PHPdoc contains just one word.

Maybe that needs a fix?
 [2021-07-19 08:03 UTC] nikic@php.net
For me the comment is always missing with save_comments=0, regardless of how it looks like. That also matches the implementation.

I suspect that the behavior you observed might be an artifact of having options like opcache.file_update_protection enabled. If it's enabled and you access a file quickly after modifying it, then it will not be cached and save_comments=0 will not take effect.
 [2021-07-19 09:25 UTC] cmb@php.net
-Status: Assigned +Status: Feedback
 [2021-07-19 09:25 UTC] cmb@php.net
> I set save_comments to 0, that was the reason of stripping this
> out.

Right.  And when you change the setting, you need to restart
Apache for that change to be effective.  However, depending on
other INI directives, the code may still be read from the file
cache, what's likely what has happened to you.

> But the behavior of that option has changed since 7.4 anyway (it
> ignored PHPdoc before?).

opcache.save_comments is only about doc block comments (i.e. those
starting with /**); other comments are always stripped.
 [2021-08-01 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2021-08-03 03:39 UTC] popov654 at yandex dot ru
-Status: No Feedback +Status: Closed
 [2021-08-03 03:39 UTC] popov654 at yandex dot ru
A checked the opcache.file_update_protection enabled setting, and it is not set in both 7.x and 8.0, so I guess it is not the case of the problem.

Any ideas?
 [2021-08-03 03:40 UTC] popov654 at yandex dot ru
-Status: Closed +Status: Assigned
 [2021-08-03 03:40 UTC] popov654 at yandex dot ru
Sorry for the delay
 [2021-08-03 03:44 UTC] popov654 at yandex dot ru
>opcache.save_comments is only about doc block comments

Can you confirm that doc block comments are really deleted on Windows 7-10 with any value of opcache.file_update_protection setting? I don't see it working. Maybe it's a bug in previous versions, not in 8.0?
 [2021-08-03 10:30 UTC] cmb@php.net
-Status: Assigned +Status: Open -Assigned To: cmb +Assigned To:
 [2021-08-03 10:30 UTC] cmb@php.net
> Can you confirm that doc block comments are really deleted on
> Windows 7-10 with any value of opcache.file_update_protection
> setting?

Yes (PHP-7.4).  As I said above, the compiled files may be read
from the file_cache, even after you made changes to the OPcache
configuration and restarted Apache.
 [2021-08-04 07:45 UTC] popov654 at yandex dot ru
Is there a way to clear that file cache for me to verify? I see there is no bug in 8.0, just to figure things out.
 [2021-08-04 09:45 UTC] cmb@php.net
The location of the file cache is set by opcache.file_cache; you
can just delete this folder (including all subitems).  Or, for
testing, you can leave the setting empty (opcache.file_cache=).
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Oct 02 19:03:43 2022 UTC