|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51732 Fileinfo __construct with explicit magic file
Submitted: 2010-05-03 21:51 UTC Modified: 2010-05-04 11:12 UTC
From: franssen dot roland at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3SVN-2010-05-03 (SVN) OS: WINNT
Private report: No CVE-ID: None
 [2010-05-03 21:51 UTC] franssen dot roland at gmail dot com
Not sure i've filled in correct PHP version; it's 5.3.1 however (packaged with xampplite 1.7.3).

Im trying to initialize a fileinfo (finfo) object with an explicit NULL value as 2nd parameter assuming it can locate the magic file by default.

Which should be fine, corresponding the documentation;
"__construct  ([  int $options = FILEINFO_NONE  [,  string $magic_file = NULL  ]] )"

Test script:
$fileInfo = new finfo(FILEINFO_MIME, null);
$fileInfo = new finfo(FILEINFO_MIME);

Expected result:
object(finfo)#2 (0) { }
object(finfo)#5 (0) { } 

Actual result:
Warning: finfo::finfo(): Failed to load magic database at ''. in *** on line ***
object(finfo)#2 (0) { }
object(finfo)#5 (0) { } 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-04 10:01 UTC]
-Status: Open +Status: Bogus
 [2010-05-04 10:01 UTC]
Why are you trying to instanciate with the second parameter to the default value when its optional?

Many functions depends internally on if 2 arguments were sent, if so then no matter of the value of that specific parameter. In this case NULL is simply a placeholder.
 [2010-05-04 10:49 UTC]
Automatic comment from SVN on behalf of pajoye
Log: - Fixed bug #51732, Fileinfo __construct or open does not work with NULL
 [2010-05-04 10:51 UTC]
-Status: Bogus +Status: Closed -Assigned To: +Assigned To: pajoye
 [2010-05-04 10:51 UTC]
Fixed in svn.

Kalle, it allows to set default value to NULL like:

function foo($v=NULL) {
$fileInfo = new finfo(FILEINFO_MIME, $v);

without having to test for $v. Other PHP functions act like that.
 [2010-05-04 10:52 UTC]
-Status: Closed +Status: Assigned -Assigned To: pajoye +Assigned To: kalle
 [2010-05-04 10:52 UTC]
However please add a note in the documentation to avoid any kind of confusions :)
 [2010-05-04 11:10 UTC]
Automatic comment from SVN on behalf of pajoye
Log: - Fix #51732, improve the doc about NULL/empty string
 [2010-05-04 11:12 UTC]
-Status: Assigned +Status: Closed
 [2010-05-04 11:12 UTC]
This bug has been fixed in SVN.

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

 [2011-02-17 22:27 UTC] alix dot axel at NOSPAM dot gmail dot com
Same behavior here.

I think the documentation should be updated to reflect this change.
 [2020-02-07 06:09 UTC]
Automatic comment on behalf of pajoye
Log: - Fix #51732, improve the doc about NULL/empty string
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 08:01:31 2024 UTC