Skip to content

getModifierNames() not reporting asymmetric visibility #19691

Closed

Description

@dalguete

Description

The following code:

<?php

class Testing
{
	public string $ok_public;
	protected string $ok_protected;
	private string $ok_private;

	public protected(set) string $wrong_public_protected_set;
	public private(set) string $wrong_public_private_set;
	protected private(set) string $wrong_protected_private_set;
}

$r = new ReflectionClass('Testing');
foreach($r->getProperties() as $rp) {
	echo $rp->getName() . ": ";
	echo $rp->getModifiers() . ": ";
	echo implode(", ", Reflection::getModifierNames($rp->getModifiers())) . "\n";
}

Resulted in this output:

ok_public: 1: public
ok_protected: 2: protected
ok_private: 4: private
wrong_public_protected_set: 2049: public
wrong_public_private_set: 4129: final, public
wrong_protected_private_set: 4130: final, protected

But I expected this output instead:

ok_public: 1: public
ok_protected: 2: protected
ok_private: 4: private
wrong_public_protected_set: 2049: public, protected_set
wrong_public_private_set: 4129: final, public, private_set
wrong_protected_private_set: 4130: final, protected, private_set

Link to run it online: https://3v4l.org/2VF1L

PHP Version

PHP Version => 8.4.10

System => Linux ip-172-31-29-183.eu-central-1.compute.internal 5.10.214-202.855.amzn2.x86_64 #1 SMP Tue Apr 9 06:57:12 UTC 2024 x86_64
Build Date => Jul 13 2025 00:21:23

Operating System

No response

Activity

  1. DanielEScherzer commented on Sep 4, 2025

    @DanielEScherzer
    Member

    So basically, asymmetric visibility flags are not reported as modifiers
    I tweaked the example to make the outputs a lot shorter and thus easier to compare

  2. DanielEScherzer commented on Sep 4, 2025

    @DanielEScherzer
    Member

    Given that 8.4 has been around for almost a year with the current behavior, I'm not sure that changing the results of getModifiers() can be done for 8.4, but this should be possible to include in 8.5

  3. changed the title [-]getModifierNames() not reporting all valid modifiers set for properties[/-] [+]getModifierNames() not reporting asymmetric visibility[/+] on Sep 4, 2025
  4. added 2 commits that reference this issue on Sep 4, 2025
  5. ndossche commented on Sep 5, 2025

    @ndossche
    Member

    @DanielEScherzer Wasn't this fixed? It probably didn't close because you didn't use the right format for the commit message: It's supposed to say "Fix GH-XXXX: TITLE"

  6. DanielEScherzer commented on Sep 5, 2025

    @DanielEScherzer
    Member

    Yeah, sorry

  7. dalguete commented on Sep 9, 2025

    @dalguete
    Author

    Given that 8.4 has been around for almost a year with the current behavior, I'm not sure that changing the results of getModifiers() can be done for 8.4, but this should be possible to include in 8.5

    Hey @DanielEScherzer, thanks for checking this. So, is this something that could be included for 8.5? I see the issue marked as closed.

  8. DanielEScherzer commented on Sep 9, 2025

    @DanielEScherzer
    Member

    It has been fixed for 8.5

  9. dalguete commented on Sep 10, 2025

    @dalguete
    Author

    @DanielEScherzer, how do you get attributions in bugs reports? I see the commit fixing it here https://github.com/php/php-src/pull/19697/files but no mention to this issue and/or reporters.

  10. DanielEScherzer commented on Sep 10, 2025

    @DanielEScherzer
    Member

    You have credit as the filer of the GitHub issue, but I don't think we normally have anything in the code to credit people who report bugs unless they also provide a test or something

  11. dalguete commented on Sep 10, 2025

    @dalguete
    Author

    Got it, makes sense. It'd be a nice addition to name everyone involved in the process from report to fix, to make a bigger community feel part of the change. But I also see the challenges that process could represent. Time to learn PHP's inner gears I think, to also include code changes. Thanks for working on this @DanielEScherzer

  12. krakjoe commented on Sep 11, 2025

    @krakjoe
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions