|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53439 DatePeriod does not expose any properties
Submitted: 2010-12-01 17:58 UTC Modified: 2017-03-24 06:47 UTC
Avg. Score:4.5 ± 0.7
Reproduced:10 of 10 (100.0%)
Same Version:4 (40.0%)
Same OS:1 (10.0%)
From: from dot php dot net at brainbox dot cz Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.3.3 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2010-12-01 17:58 UTC] from dot php dot net at brainbox dot cz
The DatePeriod instance does not expose its internal properties, thus makes impossible to extend the class.

The properties are not visible in the reflection as well. Also, when I cast the instance to array (which usually exposes all properties), no props are shown.

The draft of the test follows.

Test script:
$dp = new DatePeriod(new DateTime('2010-01-01'), new DateInterval('P1D'), 2);
$r = new ReflectionObject($dp);
$arr = (array)$dp; // cast to array to see the values of propeties

echo "Properties:\r\n";
foreach($r->getProperties() as $v) {
	echo $v->getName()."\r\n";
echo "\r\n";

echo "Methods:\r\n";
foreach($r->getMethods() as $v) {
	echo $v->getName()."\r\n";
echo "\r\n";

echo "Array cast:\r\n";
echo strtr(print_r($arr, true), "\0", '_');

Expected result:

Array cast:

Actual result:

Array cast:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-03 02:27 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: cataphract
 [2011-01-09 06:00 UTC]
-Assigned To: cataphract +Assigned To: derick
 [2011-01-09 06:00 UTC]
Reassigning to Derick, as the patch I've written is under his consideration.
 [2011-01-22 09:11 UTC]
-Type: Bug +Type: Feature/Change Request
 [2012-05-30 19:15 UTC] krebs dot seb at googlemail dot com
Anything new here? As far as I understood cataphract a patch exists. What 
happened to it?
 [2012-08-30 09:30 UTC]
Same thing happens with DateInterval
 [2014-02-06 13:51 UTC] arjen at react dot com
Fixed since 5.3.27/5.4.17, see
Probably by
 [2017-03-24 06:47 UTC]
-Status: Assigned +Status: Not a bug
 [2017-03-24 06:47 UTC]
There's no need to access the internal properties when you want to extend the class. It's entirely up to the person designing the class to expose them or not. Here they are not exposed. So if you want to extend the class you will need to use the public methods to get the information you need to handle whatever your extending class should achieve.

Therefore it'S not a bug but a feature.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Sep 28 22:01:24 2023 UTC