ID: 45167 User updated by: peter dot bex at solide-ict dot nl Reported By: peter dot bex at solide-ict dot nl Status: Assigned Bug Type: Date/time related Operating System: NetBSD/amd64 PHP Version: 5.2.6 Assigned To: derick New Comment:
Can you elaborate a bit more? Why wasn't this intended to work and what on earth are "objects of type 3"? The "(identifiers)" note doesn't help, since identifiers are to me names for things in a programming language (like variable names or class name and such). Also, shouldn't date_default_timezone_set() throw an exception in the way that the timezone class does when you pass it an invalid timezone? Silently ignoring the timezone and doing nothing is what caused me a lot of frustration and confusion in tracking what was going wrong in my script. It took me a while before I found out that this was not working (again, it is *very* unintuitive, and IMHO it qualifies as a bug). Previous Comments: ------------------------------------------------------------------------ [2008-06-04 10:27:21] [EMAIL PROTECTED] Not really a bug, as it wasn't meant to do this for anything else than timezone objects of type 3 (identifiers) - but that doesn't mean we can't add it. ------------------------------------------------------------------------ [2008-06-04 10:13:19] peter dot bex at solide-ict dot nl Description: ------------ When creating a datetime object from a string that includes timezone offset information (like "10:00:00+02:00"), the timezone object's name can not be used for creating new timezone objects or setting the default timezone. In effect, it's an "impossible object": there's no way to recreate an object like that yourself. This also means you would get unexpected results when using, for example, strftime(). If you use date_default_timezone_set to change the timezone to the object's timezone and print the date info, it will give you the wrong output. Reproduce code: --------------- <?php date_default_timezone_set('UTC'); echo "Before: ".date_default_timezone_get()."\n"; $foo = new datetime('10:00:00+02:00'); $name = $foo->getTimeZone()->getName(); echo "Setting timezone: $name\n"; date_default_timezone_set($name); echo "After: ".date_default_timezone_get()."\n"; echo "strftime: ".strftime('%H:%M:%S', $foo->format('U'))."\n"; $bar = new datetimezone($name); echo "datetimezone object name: ".$bar->getName(); ?> Expected result: ---------------- Before: UTC Setting timezone: GMT+02 After: GMT+02 strftime: 10:00:00 datetimezone object name: GMT+02 (not sure if GMT+02 is the correct timezone name. In any case, it should be some timezone name that's accepted by other timezone-related functions/classes) Actual result: -------------- Before: UTC Setting timezone: +02:00 After: UTC strftime: 08:00:00 PHP Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (+02:00)' in /path/to/index.php:10 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45167&edit=1