php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69925 ReflectionProperty::setAccessible() permanently mutates properties on DateTime
Submitted: 2015-06-25 02:30 UTC Modified: 2018-09-29 12:30 UTC
From: mark at mark-story dot com Assigned:
Status: Duplicate Package: Reflection related
PHP Version: 5.5.26 OS: MacOS 10.10.3
Private report: No CVE-ID: None
 [2015-06-25 02:30 UTC] mark at mark-story dot com
Description:
------------
The documentation for ReflectionProperty::setAccessible() implies that the change should not effect the object property visibility and this is true of user land classes, however DateTime works a bit differently, and doesn't match the behavior around userland classes.

Test script:
---------------
<?php
$subject = new DateTime('2015-06-24 22:09:00');
var_dump(isset($subject->timezone));

$reflection = new ReflectionObject($subject);
foreach ($reflection->getProperties() as $prop) {
    $prop->setAccessible(true);
    $prop->setAccessible(false);
}
var_dump(isset($subject->timezone));

Expected result:
----------------
I would expect the output to be:

bool(false)
bool(false)



Actual result:
--------------
However, it is:

bool(false)
bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-13 13:10 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-06-13 13:10 UTC] cmb@php.net
Verified: <https://3v4l.org/VHJMq>.

The behavior appears to be related to bug #69587, and if so, it
wouldn't be an issue regarding reflection, but rather DateTime.
 [2018-09-29 12:30 UTC] nikic@php.net
-Status: Verified +Status: Duplicate
 [2018-09-29 12:30 UTC] nikic@php.net
Yes, this is due to a bug in DateTime, not reflection. I'm closing this as a duplicate of bug #75232, which is about print_r, but the root cause is the same (debugging properties added in get_properties).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 06 16:01:29 2024 UTC