php.net |  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
Description:
------------
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  ]] )"
@ http://php.net/manual/en/function.finfo-open.php

Test script:
---------------
<?php
$fileInfo = new finfo(FILEINFO_MIME, null);
var_dump($fileInfo);
$fileInfo = new finfo(FILEINFO_MIME);
var_dump($fileInfo);
?>

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) { } 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-04 10:01 UTC] kalle@php.net
-Status: Open +Status: Bogus
 [2010-05-04 10:01 UTC] kalle@php.net
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] pajoye@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=298947
Log: - Fixed bug #51732, Fileinfo __construct or open does not work with NULL
 [2010-05-04 10:51 UTC] pajoye@php.net
-Status: Bogus +Status: Closed -Assigned To: +Assigned To: pajoye
 [2010-05-04 10:51 UTC] pajoye@php.net
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] pajoye@php.net
-Status: Closed +Status: Assigned -Assigned To: pajoye +Assigned To: kalle
 [2010-05-04 10:52 UTC] pajoye@php.net
However please add a note in the documentation to avoid any kind of confusions :)
 [2010-05-04 11:10 UTC] pajoye@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=298948
Log: - Fix #51732, improve the doc about NULL/empty string
 [2010-05-04 11:12 UTC] pajoye@php.net
-Status: Assigned +Status: Closed
 [2010-05-04 11:12 UTC] pajoye@php.net
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
http://snaps.php.net/.
 
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] phpdocbot@php.net
Automatic comment on behalf of pajoye
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1b6a99ef510a76e80e428fa8b124217cb6b9a45b
Log: - Fix #51732, improve the doc about NULL/empty string
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC