From:             
Operating system: Ubuntu Linux 10.04 x64
PHP version:      5.3.5
Package:          Unknown/Other Function
Bug Type:         Feature/Change Request
Bug description:Remove inconsitency of internal exceptions and user defined 
exceptions

Description:
------------
Exceptions thrown by standard PHP classes are handled inconsistently to
user defined exceptions, but should not.



An internal exception, like the one thrown by DateTime::__construct() when
supplying and invalid date string (like '9999-11-33') also trigger a
E_WARNING.

User defined Exceptions do not trigger an additional E_WARNING.



If you create a custom error handler which converts all PHP errors to
exceptions, catching internal exceptions inline therefore throws another
Exception in the custom error handler, making it impossible to really catch
the Exception.



REQUEST:

Both exception types should work consistently likewise, preferrably without
triggering an E_WARNING.



Or there should be means to distinguish an error triggered by an internal
exception from an actual error and provide data if the exception was
already handled/catched.

Test script:
---------------
<?php

//////////////////////////////////

// PHP INTERNAL EXCEPTION:

//////////////////////////////////



register_shutdown_function('shutdown');



$time           = '9999-11-33'; // obviously invalid ;-)

$timeZone       = new DateTimeZone('UTC');



try {

        $dateTime       = new DateTime($time, $timeZone);

} catch (Exception $e) {

        var_dump('Exception:', $e->getMessage());

}



echo 'END' . PHP_EOL;





function shutdown()

{

        $error = error_get_last();

        var_dump('Error ', @$error);

}

?>





<?php



//////////////////////////////////

// USER DEFINED EXCEPTION:

//////////////////////////////////



register_shutdown_function('shutdown');



try {

        throw new Exception('Foo Exception');

} catch (Exception $e) {

        var_dump('Exception:', $e->getMessage());

}



echo 'END' . PHP_EOL;





function shutdown()

{

        $error = error_get_last();

        var_dump('Error ', @$error);

}

?>

Expected result:
----------------
Output DateTime::__construct() exception:



string(10) "Exception:"

string(105) "DateTime::__construct(): Failed to parse time string
(9999-11-33) at position 9 (3): Unexpected character"

END

string(6) "Error "

array(4) {

  ["type"]=>

  int(2)

  ["message"]=>

  string(105) "DateTime::__construct(): Failed to parse time string
(9999-11-33) at position 9 (3): Unexpected character"

  ["file"]=>

  string(67)
"/home/jebner/Zend/workspaces/DefaultWorkspace7/sandbox/datetime.php"

  ["line"]=>

  int(8)

}





Output user defined exception:



string(10) "Exception:"

string(13) "Foo Exception"

END

string(6) "Error "

NULL



Actual result:
--------------
Output DateTime::__construct() exception:



string(10) "Exception:"

string(105) "DateTime::__construct(): Failed to parse time string
(9999-11-33) at position 9 (3): Unexpected character"

END

string(4) "Error "

NULL

}





Output user defined exception:



string(10) "Exception:"

string(13) "Foo Exception"

END

string(6) "Error "

NULL



-- 
Edit bug report at http://bugs.php.net/bug.php?id=54043&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54043&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54043&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54043&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54043&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54043&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54043&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54043&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54043&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54043&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54043&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54043&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54043&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54043&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54043&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54043&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54043&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54043&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54043&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54043&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54043&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54043&r=mysqlcfg

Reply via email to