[php-src] Issue #10665: ReflectionClass->getProperties: filtering using ReflectionProperty flag is not consistent
| From: | Spec1alFx | Date: | Wed, 22 Feb 2023 14:27:12 +0000 |
| Subject: | [php-src] Issue #10665: ReflectionClass->getProperties: filtering using ReflectionProperty flag is not consistent | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243782@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10665
Author: Spec1alFx
### Description
ReflectionProperty flags IS_PUBLIC, IS_PROTECTED, IS_PRIVATE, IS_READONLY, IS_STATIC are not
mutually exclusive (just IS_PUBLIC, IS_PROTECTED and IS_PRIVATE are, but a static property can be
public / protected / private / readonly and a readonly property can be public / protected / private
/ static) so using them to feed the filter parameter of ReflectionClass->getProperties is not
consistent (i.e.: you cannot filter for public static properties).
My idea to fix it with the lowest possible impact:
. add two flags IS_NOT_PRIVATE and IS_NOT_READONLY
. change the behaviour of getProperties: if you use IS_STATIC or IS_READONLY (or IS_NOT_STATIC or
IS_NOT_READONLY) then you must also specify one or more visibility flags (i.e.: IS_STATIC currently
returns all static properties regardless of visibility, with the change you'll need IS_STATIC |
IS_PUBLIC | IS_PROTECTED | IS_PRIVATE to have the same result). Other examples:
- IS_PUBLIC => all public properties (works in the same way)
- IS_STATIC | IS_PUBLIC => all static public properties (currently IS_STATIC | IS_PUBLIC returns
all public properties - static and not - PLUS all static properties - public and not)
- IS_NOT_STATIC | IS_PUBLIC => all non-static public properties
- IS_STATIC => deprecated / fatal because you should require at least one visibility flag
(breaking change, currently returns all static properties, any visibility)
- IS_STATIC | IS_NOT_STATIC | IS_PUBLIC => fatal
- IS_READONLY | IS_NOT_STATIC | IS_PROTECTED => all non-static protected readonly properties
Thank you!
Claudio
### PHP Version
PHP 8
### Operating System
_No response_