Req #65213 [Com]: cannot cast SplFileInfo to boolean

From: Date: Wed, 20 Aug 2014 13:45:22 +0000
Subject: Req #65213 [Com]: cannot cast SplFileInfo to boolean
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187199@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65213&edit=1

 ID:                 65213
 Comment by:         bpolaszek at gmail dot com
 Reported by:        fake at example dot com
 Summary:            cannot cast SplFileInfo to boolean
 Status:             Open
 Type:               Feature/Change Request
 Package:            SPL related
 PHP Version:        5.5.0
 Block user comment: N
 Private report:     N

 New Comment:

Hello,

I've just been confronted to the same problem and I also don't understand why this has
been changed to a feature request.

This issue goes against the documentation about booleans - http://php.net/manual/en/language.types.boolean.php
- and is indeed a bug, or at least an unexpected behavior with a critical matter (it just throws...
a fatal error).

Thanks for reconsidering the issue.
Beno!t POLASZEK


Previous Comments:
------------------------------------------------------------------------
[2014-05-11 00:21:56] wmpalmer at gmail dot com

I note that this has been listed as "Type: Feature/Change Request", can you explain the
rationale behind this? This clearly goes against the documented behaviour of objects in a boolean
context, so some clarification of *why* this was changed to FR could be useful.

------------------------------------------------------------------------
[2014-02-27 03:49:57] levim@php.net

This seems to have worked in PHP 5.1 when SplFileInfo was created. It has been broken since PHP 5.2

------------------------------------------------------------------------
[2013-07-07 15:56:15] laruence@php.net

change to FR

------------------------------------------------------------------------
[2013-07-06 14:23:15] fake at example dot com

Description:
------------
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:
---------------
<?php
$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 ...


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=65213&edit=1


Thread (6 messages)

« previous php.bugs (#187199) next »