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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mark at mark-story dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Thu Aug 22 12:01:27 2019 UTC