Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14687

Re: Consistency with object to boolean conversions

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: Consistency with object to boolean conversions
Date 2014-12-03 18:22 +0100
Organization solani.org
Message-ID <m5ngtb$8dj$1@solani.org> (permalink)
References <m5n8a7$gra$1@dont-email.me> <m5neof$125$6@dont-email.me> <m5ng47$k3d$1@dont-email.me>

Show all headers | View raw


Gregor Kofler wrote:

> Am 2014-12-03 um 17:46 schrieb Denis McMahon:
>> On Wed, 03 Dec 2014 15:56:23 +0100, Gregor Kofler wrote:
>>
>>> The following example should suffice to describe my problem:
>>>
>>> 50 if(!$file) {
>>> 51 }
>>> 52 else {
>>> 53    echo '$file is an object.';
>>> 54    var_dump(!$file);
>>> 55 }
>>>
>>> results in
>>>
>>> "$file is an object.
>>
>> Try casting file to boolean:
>>
>> 54    var_dump(!(boolean)$file);
>>
>> and see if that works as you expected.
>>
> Without testing I assume it would yield the same result. Found a
> possible explanation here
> 
> https://bugs.php.net/bug.php?id=65213

See also <http://3v4l.org/U8JJ4#v520>.

> it still doesn't explain why casting to boolean in the if condition
> doesn't throw an error.

Indeed.  Might that be caused by some dubious optimization (e.g. by
OPcache)?

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Consistency with object to boolean conversions Gregor Kofler <usenet@gregorkofler.com> - 2014-12-03 15:56 +0100
  Re: Consistency with object to boolean conversions "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-03 16:19 +0100
    Re: Consistency with object to boolean conversions Gregor Kofler <usenet@gregorkofler.com> - 2014-12-03 16:39 +0100
      Re: Consistency with object to boolean conversions Matthew Carter <m@ahungry.com> - 2014-12-03 11:42 -0500
        Re: Consistency with object to boolean conversions Gregor Kofler <usenet@gregorkofler.com> - 2014-12-03 18:06 +0100
          Re: Consistency with object to boolean conversions Matthew Carter <m@ahungry.com> - 2014-12-03 13:13 -0500
  Re: Consistency with object to boolean conversions Denis McMahon <denismfmcmahon@gmail.com> - 2014-12-03 16:46 +0000
    Re: Consistency with object to boolean conversions Gregor Kofler <usenet@gregorkofler.com> - 2014-12-03 18:09 +0100
      Re: Consistency with object to boolean conversions "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-03 18:22 +0100
        Re: Consistency with object to boolean conversions Gregor Kofler <usenet@gregorkofler.com> - 2014-12-03 19:12 +0100
          Re: Consistency with object to boolean conversions "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-12-03 19:30 +0100
            Re: Consistency with object to boolean conversions Gregor Kofler <usenet@gregorkofler.com> - 2014-12-03 20:58 +0100

csiph-web