php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51581 getDefaultProperties incorrect for static properties
Submitted: 2010-04-17 02:24 UTC Modified: 2010-05-26 18:45 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ChadFulton at gmail dot com Assigned: dmitry (profile)
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Mac OSx 10.6
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-04-17 02:24 UTC] ChadFulton at gmail dot com
Description:
------------
The array ReflectionClass's getDefaultProperties() method changes for static 
properties, depending upon what value the static property currently holds.

I suppose there is an argument to be made that this is expected/desired, since 
static properties are meant to hold across all instances of the class. However, it 
doesn't seem like it necessarily fits as part of a function to get the *default* 
property.

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

class foo {
    static public $bar = 'true default value';
}

$r = new ReflectionClass('foo');
print_r($r->getDefaultProperties());

foo::$bar = 'new static value, no longer default though';

print_r($r->getDefaultProperties());

?>

Expected result:
----------------
Array
(
    [bar] => true default value
)
Array
(
    [bar] => true default value
)

Actual result:
--------------
Array
(
    [bar] => true default value
)
Array
(
    [bar] => new static value, no longer default though
)

Patches

fix-reflection-of-default-static-members (last revision 2010-05-12 13:45 UTC by mike@php.net)
fix-refs-to-default-static-members (last revision 2010-05-12 13:42 UTC by mike@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 15:42 UTC] mike@php.net
The following patch has been added/updated:

Patch Name: fix-refs-to-default-static-members
Revision:   1273671720
URL:        http://bugs.php.net/patch-display.php?bug=51581&patch=fix-refs-to-default-static-members&revision=1273671720
 [2010-05-12 15:45 UTC] mike@php.net
The following patch has been added/updated:

Patch Name: fix-reflection-of-default-static-members
Revision:   1273671935
URL:        http://bugs.php.net/patch-display.php?bug=51581&patch=fix-reflection-of-default-static-members&revision=1273671935
 [2010-05-12 15:45 UTC] mike@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2010-05-12 15:45 UTC] mike@php.net
Dmitry, could you please review the fix-refs-to-default-static-members patch?

Thank you.
 [2010-05-13 07:20 UTC] ChadFulton at gmail dot com
Thanks for taking this issue up!
 [2010-05-21 11:29 UTC] mike@php.net
-Package: Reflection related +Package: Scripting Engine problem
 [2010-05-21 11:29 UTC] mike@php.net
IMO actually a scripting engine problem.
 [2010-05-26 18:45 UTC] dmitry@php.net
-Status: Assigned +Status: Wont fix
 [2010-05-26 18:45 UTC] dmitry@php.net
PHP don't have to keep the default values of static class variables of user-defined classes. Of course it might be used in ext/Reflection but it would require less-efficient and more-memory-consumption implementation which would affect any php script which use classes with static properties.

I would stay the behaviour as is and would disable access to default static properties values which is incorrect anyway.
 [2012-07-06 21:50 UTC] dev at pp3345 dot de
Hello,

I was going to report a similar bug as I'm experiencing the same problem. I actually believe that this problem should be 
fixed as it could be quite useful in some cases to retrieve the default values of static class properties. It would be nice 
if you could think about fixing this again. I'm not sure if this is easily possible, but a solution without raising memory 
consumption for everyone could be an additional ini-setting that enables and disables tracking of the default values of 
static properties.
 [2013-01-19 14:45 UTC] googleguy@php.net
Automatic comment from SVN on behalf of googleguy
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=329237
Log: Added note to documentat that this method is only intended to work with internal classes for getting the default value of static class properties.

Fixes bug #63370 also references bug #51581
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Aug 23 08:01:26 2019 UTC