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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 34 = ?
Subscribe to this entry?

 
 [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: Mon Aug 19 01:01:26 2019 UTC