php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45038 Crash when using DateTimeZone object returned by Date::getTimezone
Submitted: 2008-05-19 10:13 UTC Modified: 2008-07-08 17:53 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:3 (75.0%)
From: astax dot t at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
 [2008-05-19 10:13 UTC] astax dot t at gmail dot com
Description:
------------
Crash when using DateTimeZone object, previously returned by DateTime::getTimezone()


This worked fine in PHP 5.2.5
Probably this is related to how DateTimeZone object is returned:

This code returns different results in 5.2.5 and 5.2.6

$old_tz = $d->getTimezone();
$d->setTimezone(new DateTimeZone('UTC'));
echo $old_tz->getName();

5.2.6 returns 'UTC', while 5.2.5 returns 'Asia/Novosibirsk' (my current timezone). Having in mind how objects in PHP5 are returned, I can accept this, but this must be documented properly and shouldn't cause crash.

Reproduce code:
---------------
$d = new DateTime();
$old_tz = $d->getTimezone();
$d->setTimezone(new DateTimeZone('UTC'));
// setDate() and setTime() may go here - just for this example to make some sense
$d->setTimezone($old_tz);
echo "Success";

Expected result:
----------------
Success

Actual result:
--------------
PHP interpreter crashes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-27 08:23 UTC] astax dot t at gmail dot com
Any chance for this to be fixed?
 [2008-05-27 10:46 UTC] felipe@php.net
Wait and rely. :)

Assigned to maintainer.
 [2008-05-31 10:54 UTC] thekid@php.net
Another reproduce script:

<?php
  $date= date_create();
  var_dump($date);

  $origtz= date_timezone_get($date);
  var_dump($origtz);

  date_timezone_set($date, timezone_open('GMT'));
  var_dump($date);

  $formatted= date_format($date, 'r');
  var_dump($formatted);

  date_timezone_set($date, $origtz);
  var_dump($date);

  echo $formatted;
?>

== Output ==
  object(DateTime)#1 (0) {
  }
  object(DateTimeZone)#2 (0) {
  }
  object(DateTime)#1 (0) {
  }
  string(31) "Sat, 31 May 2008 10:49:27 +0000"
  Segmentation fault
== /Output ==

PHP 5.2.6 (cgi) (built: May 19 2008 09:18:35)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

 [2008-07-01 03:27 UTC] levi at alliancesoftware dot com dot au
About as simple as you can get:

<? $dt = new DateTime(); $dt->setTimezone($dt->getTimezone()); ?>


Segfaults on FC9 x86_64 CLI compiled from source.
(However, silently succeeds on FC8 x86 compiled from source).
 [2008-07-01 07:59 UTC] peter dot bex at solide-ict dot nl
I can verify that it crashes on PHP 5.2.6 under NetBSD/amd64 (-current from April), so most likely it's architecture-specific if it works on i386.
 [2008-07-08 17:53 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC