# Conversion of SplFileInfo instances to boolean

- Thread: https://externals.io/message/79399
- Original archive: https://news-web.php.net/php.internals/79399
- Started by Christoph Becker on 2014-12-03T20:35:41+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #79399 — Christoph Becker — 2014-12-03T20:35:41+00:00

URL: https://externals.io/message/79399#79399

Hello internals,

today I stumbled over issue #65213[1] which has been reported as a bug,
but was changed to a feature request without any hint why the conversion
of SplFileInfo instances to boolean throws a catchable fatal error.

Even worse, due to optimizations in OPcache (and maybe other optimizers
as well), this does not always happen.  Consider the following snippet:

    <?php

    $o = new SplFileObject('.');
    if (!$o) {
    } else {
        var_dump(!$o);
    }

Without any optimization this throws the error in line 4 (the if
clause); with OPcache the error is thrown in line 6.  Apparently that is
caused by a optimization where BOOL_NOT,JMPZ is converted to NOP,JMPNZ[2].

IOW: with OPcache enabled `if (!$o)` works fine, but without OPcache it
is an error.  IMHO both should behave identically.

[1] <https://bugs.php.net/bug.php?id=65213>
[2] <http://lxr.php.net/xref/PHP_5_5/ext/opcache/Optimizer/block_pass.c#816>

-- 
Christoph M. Becker

---

## #79400 — Peter Cowburn — 2014-12-03T21:09:42+00:00

URL: https://externals.io/message/79399#79400 · In reply to: #79399

> Hello internals,
>
> today I stumbled over issue #65213[1] which has been reported as a bug,
> but was changed to a feature request without any hint why the conversion
> of SplFileInfo instances to boolean throws a catchable fatal error.
>
> Even worse, due to optimizations in OPcache (and maybe other optimizers
> as well), this does not always happen.  Consider the following snippet:
>
>     <?php
>
>     $o = new SplFileObject('.');
>     if (!$o) {
>     } else {
>         var_dump(!$o);
>     }
>
> Without any optimization this throws the error in line 4 (the if
> clause); with OPcache the error is thrown in line 6.  Apparently that is
> caused by a optimization where BOOL_NOT,JMPZ is converted to NOP,JMPNZ[2].
>
> IOW: with OPcache enabled `if (!$o)` works fine, but without OPcache it
> is an error.  IMHO both should behave identically.
>
> [1] <https://bugs.php.net/bug.php?id=65213>
>

This looks fixed in master (https://github.com/php/php-src/commit/8904f72
<https://github.com/php/php-src/commit/8904f72d7c47253345f7039afd8ca754442c7e34>
).


> [2] <
> http://lxr.php.net/xref/PHP_5_5/ext/opcache/Optimizer/block_pass.c#816>
>
> --
> Christoph M. Becker

---

## #79404 — Christoph Becker — 2014-12-03T22:09:45+00:00

URL: https://externals.io/message/79399#79404 · In reply to: #79400

Peter Cowburn wrote:

> 
> 
> > […]
> 
> This looks fixed in master (https://github.com/php/php-src/commit/8904f72
> <https://github.com/php/php-src/commit/8904f72d7c47253345f7039afd8ca754442c7e34>
> ).

Indeed, thanks.  <http://3v4l.org/1fHVC> confirms that.  However, if the
former behavior is regarded as a bug, shouldn't it be fixed for PHP 5.5
and PHP 5.6 as well?

Anyhow, the bug report/feature request might be closed.

-- 
Christoph M. Becker
