Unable to detect error from finfo constructor

Bug #61173 Unable to detect error from finfo constructor
Submitted: 2012-02-23 20:45 UTC Modified: 2012-03-07 07:45 UTC
From: vrana@php.net Assigned: cataphract (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.4.0RC8 OS: Irrelevant
Private report: No CVE-ID: None

 [2012-02-23 20:45 UTC] vrana@php.net

Description:
------------
There is currently no way to detect error in finfo::__construct() other than defining own set_error_handler(). It should throw an exception in case of an error.

new finfo() always creates the object but this object is unusable if constructor doesn't succeed.

Test script:
---------------
$finfo = null;
try {
	$finfo = new finfo(1, '', false);
} catch (Exception $e) {
	echo "Error creating finfo.\n";
}
var_dump($finfo);


Expected result:
----------------
Error creating finfo.
NULL


Actual result:
--------------
object(finfo)#1 (0) {
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2012-02-24 08:34 UTC] cataphract@php.net

The manual suggests new should give NULL in case of error: http://php.net/finfo_open . Why do you expect the exception? In any case, there's of course a bug because new is giving an object.

 [2012-02-24 10:01 UTC] cataphract@php.net

-Status: Feedback +Status: Closed -Assigned To: +Assigned To: cataphract

 [2012-02-24 10:37 UTC] pajoye@php.net

Please do not close bug when the fix has not been applied to 5.4, so we have a way 
to do not forget it as soon as 5.4-final is out.

Cheers,

 [2012-02-24 10:37 UTC] pajoye@php.net

-Status: Closed +Status: Assigned

 [2012-03-07 07:45 UTC] stas@php.net

-Status: Assigned +Status: Closed