php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50242 Creating a DateTime object causes error_get_last() return value to reset
Submitted: 2009-11-20 13:16 UTC Modified: 2010-03-07 14:15 UTC
From: jussi at growvc dot com Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.2 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jussi at growvc dot com
New email:
PHP Version: OS:

 

 [2009-11-20 13:16 UTC] jussi at growvc dot com
Description:
------------
It seems that calling the DateTime class constructor causes an error
accumulated in error_get_last() to be cleared.

I am using a 64bit Linux (Ubuntu 9.10) with PHP 5.2.11 built by
dotdeb.org (unfortunately phpinfo() of their version doesn't give up
configure options). The problem reproduces with a default php.ini,
both as Apache module and on CLI.

I was also able do reproduce this on another system with another PHP
version (5.2.9, also a dotdeb build).

Reproduce code:
---------------
@trigger_error('foo');
echo (is_array(error_get_last())?'Error':'No error') . "\n";

$dt = new DateTime();
echo (is_array(error_get_last())?'Error':'No error') . "\n";

Expected result:
----------------
Error
Error


Actual result:
--------------
Error
No error


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-20 18:00 UTC] jani@php.net
Happens only in PHP_5_2 branch.
 [2010-03-07 14:15 UTC] derick@php.net
-Status: Assigned +Status: Bogus
 [2010-03-07 14:15 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is not a bug, this is how PHP's internal error handling works (in 5.2). Errors are only kept internally until some mechanism resets it. The data is only guaranteed to be there *directly* after an error has been created. In PHP 5.3 and up, conversion from warnings/errors to exceptions is done differently so therefore it works better there.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC