Skip to content

Conversation

@cmb69
Copy link
Member

@cmb69 cmb69 commented Apr 9, 2020

https://bugs.php.net/bug.php?id=69804

ReflectionClass allows reading of the values of private and protected
constants, and also to get private and protected static methods.
Therefore getting the values of private and protected static properties
is also permissible, especially since ::getStaticProperties() already
allows to do so.

`ReflectionClass` allows reading of the values of private and protected
constants, and also to get private and protected static methods.
Therefore getting the values of private and protected static properties
is also permissible, especially since `::getStaticProperties()` already
allows to do so.
@nikic
Copy link
Member

nikic commented Apr 9, 2020

What about setStaticPropertyValue?

@cmb69
Copy link
Member Author

cmb69 commented Apr 9, 2020

What about setStaticPropertyValue?

Well, you can't invoke (static) private/protected methods without making them accessible first, so I think setStaticPropertyValue shouldn't support that (unless some mechanism would be introduced to make a static property accessible from ReflectionClass).

@nikic
Copy link
Member

nikic commented Apr 9, 2020

@cmb69 Doesn't the same argument apply to getStaticPropertyValue() as well?

TBH I don't understand why these methods are a thing at all, they don't seem to provide anything on top of Foo::$$bar.

@cmb69
Copy link
Member Author

cmb69 commented Apr 9, 2020

You can read private constants via ReflectionClass, but you can't read private static properties: https://3v4l.org/GdKJn. Also, ReflectionClass::getStaticProperties() reads private and protected properties, but ReflectionClass::getStaticPropertyValue() does not: https://3v4l.org/om1lZ. IMHO, this is very inconsistent, and changing that would at least make ReflectionClass::getStaticPropertyValue() useful.

Forbidding to modify private and protected properties renders this
method useless, as modifying public properties can be done directly.
@cmb69
Copy link
Member Author

cmb69 commented Apr 15, 2020

What about setStaticPropertyValue?

Well, after reconsideration I agree that it makes no sense to restrict this method to public properties (see also https://www.php.net/manual/en/reflectionclass.setstaticpropertyvalue.php#114740). PR updated.

Can this still target PHP-7.3? The change could break some tests/expectations.

@nikic
Copy link
Member

nikic commented Apr 17, 2020

Can this still target PHP-7.3? The change could break some tests/expectations.

I think it's best to leave 7.3 alone.

@cmb69
Copy link
Member Author

cmb69 commented Apr 17, 2020

I think it's best to leave 7.3 alone.

Fine. :) But for 7.4 I'm hitting https://bugs.php.net/79487. :(

@cmb69
Copy link
Member Author

cmb69 commented Jun 24, 2020

Applied as 26aefb7. Thanks!

@cmb69 cmb69 closed this Jun 24, 2020
@cmb69 cmb69 deleted the cmb/69804 branch June 24, 2020 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants