Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14688
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Consistency with object to boolean conversions |
| Date | 2014-12-03 19:12 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <m5njqb$4cf$1@dont-email.me> (permalink) |
| References | <m5n8a7$gra$1@dont-email.me> <m5neof$125$6@dont-email.me> <m5ng47$k3d$1@dont-email.me> <m5ngtb$8dj$1@solani.org> |
Am 2014-12-03 um 18:22 schrieb Christoph M. Becker:
> 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)?
Indeed. Since my 5.5.9 shows the above behaviour but 5.4.35 already
fails at line 50.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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