Bug #50559 [Com]: Clone is not implemented for DateInterval and DatePeriod

2013-08-07 Thread kofkof at laposte dot net
Edit report at https://bugs.php.net/bug.php?id=50559&edit=1

 ID: 50559
 Comment by: kofkof at laposte dot net
 Reported by:sr at emini dot dk
 Summary:Clone is not implemented for DateInterval and
 DatePeriod
 Status: Assigned
 Type:   Bug
 Package:Date/time related
 Operating System:   Fedora 10
 PHP Version:5.3.1
 Assigned To:derick
 Block user comment: N
 Private report: N

 New Comment:

If I swap lines 2 and 3 in the bug description code, this way:

$dateInterval1 = new DateInterval('P1D');
var_dump($dateInterval1);
$dateInterval2 = clone $dateInterval1;
var_dump($dateInterval2);

... then $dateInterval2 is not empty (as displayed by var_dump()). However, 
when 
I try to use it:

$d = new DateTime();
$d->add($dateInterval2);

... then I get "Warning: DateTime::add(): The DateInterval object has not been 
correctly initialized by its constructor in..."

(PHP 5.4.11 on Mac OS 10.7.5)


Previous Comments:

[2011-05-06 11:14:51] giorgio dot liscio at email dot it

on windows 7 + apache2 + php 5.3.6

apache crashes when

$cl = clone $dateIntervalObject;
in any scope, in any function, on an empty page too.

i tried to provide a backtrace but something goes wrong

i can't convert the generated .dmp file to a readable dump to attach here


[2010-03-08 10:59:43] yoarvi at gmail dot com

Did you forget to attach the script?


[2010-03-07 20:24:53] der...@php.net

This patch causes issues. If I try the attached script I end up in an infinite 
loop.


[2010-01-27 13:47:00] yoarvi at gmail dot com

The following patch implements the logic to clone DatePeriod and DateInterval 
objects and also includes a test case:

Index: ext/date/php_date.c
===
--- ext/date/php_date.c (revision 293574)
+++ ext/date/php_date.c (working copy)
@@ -2213,7 +2213,9 @@

zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std, 
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
 
-   /** FIX ME ADD CLONE STUFF **/
+   new_obj->diff = timelib_rel_time_clone(old_obj->diff);
+   new_obj->initialized = 1;
+
return new_ov;
 }
 
@@ -2283,7 +2285,27 @@

zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std, 
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
 
-   /** FIX ME ADD CLONE STUFF **/
+   new_obj->start = timelib_time_ctor();
+   *new_obj->start = *old_obj->start;
+   if (old_obj->start->tz_abbr) {
+   new_obj->start->tz_abbr = strdup(old_obj->start->tz_abbr);
+   }
+   if (old_obj->start->tz_info) {
+   new_obj->start->tz_info = old_obj->start->tz_info;
+   }
+   new_obj->end = timelib_time_ctor();
+   *new_obj->end = *old_obj->end;
+   if (old_obj->end->tz_abbr) {
+   new_obj->end->tz_abbr = strdup(old_obj->end->tz_abbr);
+   }
+   if (old_obj->end->tz_info) {
+   new_obj->end->tz_info = old_obj->end->tz_info;
+   }
+   new_obj->interval = timelib_rel_time_clone(old_obj->interval);
+   new_obj->recurrences = old_obj->recurrences;
+   new_obj->include_start_date = old_obj->include_start_date;
+   new_obj->initialized = 1;
+
return new_ov;
 }

Index: ext/date/tests/bug50559.phpt
===
--- ext/date/tests/bug50559.phpt(revision 0)
+++ ext/date/tests/bug50559.phpt(revision 0)
@@ -0,0 +1,131 @@
+--TEST--
+Bug #50559 (Clone is not implemented for DateInterval and DatePeriod)
+--FILE--
+format("l Y-m-d H:i:s\n");
+}
+
+echo "\n";
+echo "DatePeriod (clone)\n";
+foreach ($datePeriod2 as $p) {
+   echo $p->format("l Y-m-d H:i:s\n");
+}
+echo "\n";
+?>
+--EXPECT--
+
+DateInterval (original)
+object(DateInterval)#1 (8) {
+  ["y"]=>
+  int(0)
+  ["m"]=>
+  int(0)
+  ["d"]=>
+  int(1)
+  ["h"]=>
+  int(0)
+  ["i"]=>
+  int(0)
+  ["s"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  int(0)
+}
+
+DateInterval (clone)
+object(DateInterval)#2 (8) {
+  ["y"]=>
+  int(0)
+  ["m"]=>
+  int(0)
+  ["d"]=>
+  int(1)
+  ["h"]=>
+  int(0)
+  ["i"]=>
+  int(0)
+  ["s"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  int(0)
+}
+
+DatePeriod (original)
+Thursday 2008-01-31 00:00:00
+Thursday 2008-02-28 00:00:00
+Thursday 2008-03-27 00:00:00
+Thursday 2008-04-24 00:00:00
+Thursday 2008-05-29 00:00:00
+Thursday 2008-06-26 00:00:00
+Thursday 2008-07-31 00:00:00
+Thursday 2008-08-28 00:00:00
+Thursday 2008-0

Bug #50559 [Com]: Clone is not implemented for DateInterval and DatePeriod

2011-05-06 Thread giorgio dot liscio at email dot it
Edit report at http://bugs.php.net/bug.php?id=50559&edit=1

 ID: 50559
 Comment by: giorgio dot liscio at email dot it
 Reported by:sr at emini dot dk
 Summary:Clone is not implemented for DateInterval and
 DatePeriod
 Status: Assigned
 Type:   Bug
 Package:Date/time related
 Operating System:   Fedora 10
 PHP Version:5.3.1
 Assigned To:derick
 Block user comment: N
 Private report: N

 New Comment:

on windows 7 + apache2 + php 5.3.6



apache crashes when



$cl = clone $dateIntervalObject;

in any scope, in any function, on an empty page too.



i tried to provide a backtrace but something goes wrong



i can't convert the generated .dmp file to a readable dump to attach
here


Previous Comments:

[2010-03-08 10:59:43] yoarvi at gmail dot com

Did you forget to attach the script?


[2010-03-07 20:24:53] der...@php.net

This patch causes issues. If I try the attached script I end up in an
infinite loop.


[2010-01-27 13:47:00] yoarvi at gmail dot com

The following patch implements the logic to clone DatePeriod and
DateInterval objects and also includes a test case:



Index: ext/date/php_date.c

===

--- ext/date/php_date.c (revision 293574)

+++ ext/date/php_date.c (working copy)

@@ -2213,7 +2213,9 @@



zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);

 

-   /** FIX ME ADD CLONE STUFF **/

+   new_obj->diff = timelib_rel_time_clone(old_obj->diff);

+   new_obj->initialized = 1;

+

return new_ov;

 }

 

@@ -2283,7 +2285,27 @@



zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);

 

-   /** FIX ME ADD CLONE STUFF **/

+   new_obj->start = timelib_time_ctor();

+   *new_obj->start = *old_obj->start;

+   if (old_obj->start->tz_abbr) {

+   new_obj->start->tz_abbr = strdup(old_obj->start->tz_abbr);

+   }

+   if (old_obj->start->tz_info) {

+   new_obj->start->tz_info = old_obj->start->tz_info;

+   }

+   new_obj->end = timelib_time_ctor();

+   *new_obj->end = *old_obj->end;

+   if (old_obj->end->tz_abbr) {

+   new_obj->end->tz_abbr = strdup(old_obj->end->tz_abbr);

+   }

+   if (old_obj->end->tz_info) {

+   new_obj->end->tz_info = old_obj->end->tz_info;

+   }

+   new_obj->interval = timelib_rel_time_clone(old_obj->interval);

+   new_obj->recurrences = old_obj->recurrences;

+   new_obj->include_start_date = old_obj->include_start_date;

+   new_obj->initialized = 1;

+

return new_ov;

 }



Index: ext/date/tests/bug50559.phpt

===

--- ext/date/tests/bug50559.phpt(revision 0)

+++ ext/date/tests/bug50559.phpt(revision 0)

@@ -0,0 +1,131 @@

+--TEST--

+Bug #50559 (Clone is not implemented for DateInterval and DatePeriod)

+--FILE--

+format("l Y-m-d H:i:s\n");

+}

+

+echo "\n";

+echo "DatePeriod (clone)\n";

+foreach ($datePeriod2 as $p) {

+   echo $p->format("l Y-m-d H:i:s\n");

+}

+echo "\n";

+?>

+--EXPECT--

+

+DateInterval (original)

+object(DateInterval)#1 (8) {

+  ["y"]=>

+  int(0)

+  ["m"]=>

+  int(0)

+  ["d"]=>

+  int(1)

+  ["h"]=>

+  int(0)

+  ["i"]=>

+  int(0)

+  ["s"]=>

+  int(0)

+  ["invert"]=>

+  int(0)

+  ["days"]=>

+  int(0)

+}

+

+DateInterval (clone)

+object(DateInterval)#2 (8) {

+  ["y"]=>

+  int(0)

+  ["m"]=>

+  int(0)

+  ["d"]=>

+  int(1)

+  ["h"]=>

+  int(0)

+  ["i"]=>

+  int(0)

+  ["s"]=>

+  int(0)

+  ["invert"]=>

+  int(0)

+  ["days"]=>

+  int(0)

+}

+

+DatePeriod (original)

+Thursday 2008-01-31 00:00:00

+Thursday 2008-02-28 00:00:00

+Thursday 2008-03-27 00:00:00

+Thursday 2008-04-24 00:00:00

+Thursday 2008-05-29 00:00:00

+Thursday 2008-06-26 00:00:00

+Thursday 2008-07-31 00:00:00

+Thursday 2008-08-28 00:00:00

+Thursday 2008-09-25 00:00:00

+Thursday 2008-10-30 00:00:00

+Thursday 2008-11-27 00:00:00

+Thursday 2008-12-25 00:00:00

+Thursday 2009-01-29 00:00:00

+Thursday 2009-02-26 00:00:00

+Thursday 2009-03-26 00:00:00

+Thursday 2009-04-30 00:00:00

+Thursday 2009-05-28 00:00:00

+Thursday 2009-06-25 00:00:00

+Thursday 2009-07-30 00:00:00

+Thursday 2009-08-27 00:00:00

+Thursday 2009-09-24 00:00:00

+Thursday 2009-10-29 00:00:00

+Thursday 2009-11-26 00:00:00

+Thursday 2009-12-31 00:00:00

+

Bug #50559 [Com]: Clone is not implemented for DateInterval and DatePeriod

2010-03-08 Thread
Edit report at http://bugs.php.net/bug.php?id=50559&edit=1

 ID:   50559
 Comment by:   
 Reported by:  sr at emini dot dk
 Summary:  Clone is not implemented for DateInterval and
   DatePeriod
 Status:   Assigned
 Type: Bug
 Package:  Date/time related
 Operating System: Fedora 10
 PHP Version:  5.3.1
 Assigned To:  derick

 New Comment:

Did you forget to attach the script?


Previous Comments:

[2010-03-07 20:24:53] der...@php.net

This patch causes issues. If I try the attached script I end up in an
infinite loop.


[2010-01-27 13:47:00] yoarvi at gmail dot com

The following patch implements the logic to clone DatePeriod and
DateInterval objects and also includes a test case:



Index: ext/date/php_date.c

===

--- ext/date/php_date.c (revision 293574)

+++ ext/date/php_date.c (working copy)

@@ -2213,7 +2213,9 @@



zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);

 

-   /** FIX ME ADD CLONE STUFF **/

+   new_obj->diff = timelib_rel_time_clone(old_obj->diff);

+   new_obj->initialized = 1;

+

return new_ov;

 }

 

@@ -2283,7 +2285,27 @@



zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);

 

-   /** FIX ME ADD CLONE STUFF **/

+   new_obj->start = timelib_time_ctor();

+   *new_obj->start = *old_obj->start;

+   if (old_obj->start->tz_abbr) {

+   new_obj->start->tz_abbr = strdup(old_obj->start->tz_abbr);

+   }

+   if (old_obj->start->tz_info) {

+   new_obj->start->tz_info = old_obj->start->tz_info;

+   }

+   new_obj->end = timelib_time_ctor();

+   *new_obj->end = *old_obj->end;

+   if (old_obj->end->tz_abbr) {

+   new_obj->end->tz_abbr = strdup(old_obj->end->tz_abbr);

+   }

+   if (old_obj->end->tz_info) {

+   new_obj->end->tz_info = old_obj->end->tz_info;

+   }

+   new_obj->interval = timelib_rel_time_clone(old_obj->interval);

+   new_obj->recurrences = old_obj->recurrences;

+   new_obj->include_start_date = old_obj->include_start_date;

+   new_obj->initialized = 1;

+

return new_ov;

 }



Index: ext/date/tests/bug50559.phpt

===

--- ext/date/tests/bug50559.phpt(revision 0)

+++ ext/date/tests/bug50559.phpt(revision 0)

@@ -0,0 +1,131 @@

+--TEST--

+Bug #50559 (Clone is not implemented for DateInterval and DatePeriod)

+--FILE--

+format("l Y-m-d H:i:s\n");

+}

+

+echo "\n";

+echo "DatePeriod (clone)\n";

+foreach ($datePeriod2 as $p) {

+   echo $p->format("l Y-m-d H:i:s\n");

+}

+echo "\n";

+?>

+--EXPECT--

+

+DateInterval (original)

+object(DateInterval)#1 (8) {

+  ["y"]=>

+  int(0)

+  ["m"]=>

+  int(0)

+  ["d"]=>

+  int(1)

+  ["h"]=>

+  int(0)

+  ["i"]=>

+  int(0)

+  ["s"]=>

+  int(0)

+  ["invert"]=>

+  int(0)

+  ["days"]=>

+  int(0)

+}

+

+DateInterval (clone)

+object(DateInterval)#2 (8) {

+  ["y"]=>

+  int(0)

+  ["m"]=>

+  int(0)

+  ["d"]=>

+  int(1)

+  ["h"]=>

+  int(0)

+  ["i"]=>

+  int(0)

+  ["s"]=>

+  int(0)

+  ["invert"]=>

+  int(0)

+  ["days"]=>

+  int(0)

+}

+

+DatePeriod (original)

+Thursday 2008-01-31 00:00:00

+Thursday 2008-02-28 00:00:00

+Thursday 2008-03-27 00:00:00

+Thursday 2008-04-24 00:00:00

+Thursday 2008-05-29 00:00:00

+Thursday 2008-06-26 00:00:00

+Thursday 2008-07-31 00:00:00

+Thursday 2008-08-28 00:00:00

+Thursday 2008-09-25 00:00:00

+Thursday 2008-10-30 00:00:00

+Thursday 2008-11-27 00:00:00

+Thursday 2008-12-25 00:00:00

+Thursday 2009-01-29 00:00:00

+Thursday 2009-02-26 00:00:00

+Thursday 2009-03-26 00:00:00

+Thursday 2009-04-30 00:00:00

+Thursday 2009-05-28 00:00:00

+Thursday 2009-06-25 00:00:00

+Thursday 2009-07-30 00:00:00

+Thursday 2009-08-27 00:00:00

+Thursday 2009-09-24 00:00:00

+Thursday 2009-10-29 00:00:00

+Thursday 2009-11-26 00:00:00

+Thursday 2009-12-31 00:00:00

+

+DatePeriod (clone)

+Thursday 2008-01-31 00:00:00

+Thursday 2008-02-28 00:00:00

+Thursday 2008-03-27 00:00:00

+Thursday 2008-04-24 00:00:00

+Thursday 2008-05-29 00:00:00

+Thursday 2008-06-26 00:00:00

+Thursday 2008-07-31 00:00:00

+Thursday 2008-08-28 00:00:00

+Thursday 2008-09-25 00:00:00

+Thursday 2008-10-30 00:00:00

+Thursday 2008-11-27 00:00:00

+Thursday 2008-12-25 00:00:00

+Thursday 2009-01-29 00:00:00

+Thursday 2009-02-26 00:00:00

+Thursday 2009-03-26 00:00:00

+Thursday 2009-04-3