|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65213 cannot cast SplFileInfo to boolean
Submitted: 2013-07-06 14:23 UTC Modified: 2013-07-07 15:56 UTC
Avg. Score:4.5 ± 0.7
Reproduced:12 of 12 (100.0%)
Same Version:4 (33.3%)
Same OS:3 (25.0%)
From: fake at example dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.5.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
23 + 14 = ?
Subscribe to this entry?

 [2013-07-06 14:23 UTC] fake at example dot com
Casting an instance of SplFileInfo to boolean throws an exception. It should behave like other objects, where the cast always results in boolean true without throwing. Otherwise, it breaks common code like

if (!$myObj) {...}

Test script:
$o = new SplFileInfo('.');
var_dump((bool) $o);

Expected result:
I expect (bool) true as output.

Actual result:
Catchable fatal error: Object of class SplFileInfo could not be converted to boolean in ...


Add a Patch

Pull Requests

Add a Pull Request