Bug #69804 [PATCH]: ReflectionClass::getStaticPropertyValue() throws exception on protected props

From: Date: Wed, 15 Apr 2020 16:36:26 +0000
Subject: Bug #69804 [PATCH]: ReflectionClass::getStaticPropertyValue() throws exception on protected props
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226592@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69804&edit=1

 ID:                 69804
 Patch added by:     cmb@php.net
 Reported by:        grzegorz129 at gmail dot com
 Summary:            ReflectionClass::getStaticPropertyValue() throws
                     exception on protected props
 Status:             Assigned
 Type:               Bug
 Package:            Reflection related
 Operating System:   OSX, Linux
 PHP Version:        7.0Git-2015-06-11 (snap)
 Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

The following pull request has been associated:

Patch Name: Fix #69804: ::getStaticPropertyValue() throws on protected props
On GitHub:  https://github.com/php/php-src/pull/5367
Patch:      https://github.com/php/php-src/pull/5367.patch


Previous Comments:
------------------------------------------------------------------------
[2015-06-13 23:13:38] bwoebi@php.net

@laruence: IMO this is a bug.

It should just allow getStaticPropertyValue() to actually work on protected variables too. Or remove
protected variables from getStaticProperties().

It definitely is a major inconsistency which should be considered as bug.

@grzegorz129: But don't expect ReflectionProperty::setAccessible() could change anything here.
setAccessible() only affects the scope of that particular ReflectionProperty object.

------------------------------------------------------------------------
[2015-06-13 22:09:34] grzegorz129 at gmail dot com

@laruence: I saw your another comment about method behaving similar in PHP 5.6 - you're right,
but I think implementation should be fixed instead of documentation, because that behaviour is
little strange.
It shouldn't break any code - who's calling setAccess(true) and expect it wouldn't
change that? :D

------------------------------------------------------------------------
[2015-06-12 01:33:48] laruence@php.net

hmm, setAccess doesn't change the property_info...  will think about a proper hack fix..

------------------------------------------------------------------------
[2015-06-11 22:19:25] grzegorz129 at gmail dot com

Description:
------------
Trying to use ReflectionClass::getStaticPropertyValue() on protected static properties of class
results in exception with information about non existing property. However
ReflectionClass::getStaticProperties() returns that property with correct value on all supported PHP
versions.
Adding ReflectionProperty::setAccessible(true) doesn't affect final effect.

Of course I can use getStaticProperties() array, but maybe getStaticPropertyValue() should be fixed
or at least some documentation note be added?

After research I found it's related to #54620, but maybe setAccessible() should also affect
getStaticPropertyValue() call?

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

class foo {
    protected static $test = 'bar';
}

$classReflection = new ReflectionClass('foo');
$property = $classReflection->getProperty('test');
var_dump($property);

$property->setAccessible(true); //Changes nothing in that case
var_dump($classReflection->getStaticProperties());
var_dump($classReflection->getStaticPropertyValue('test'));

Actual result:
--------------
http://3v4l.org/om1lZ


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69804&edit=1


Thread (5 messages)

« previous php.bugs (#226592) next »