Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Matthew Carter Newsgroups: comp.lang.php Subject: Re: Consistency with object to boolean conversions Date: Wed, 03 Dec 2014 11:42:49 -0500 Organization: Ahungry (http://ahungry.com) Lines: 61 Message-ID: <87d280ofau.fsf@ahungry.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7c986cd4736462de309a749b207746fe"; logging-data="12853"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Lb9v8UHk9WvnRdEWdDYFU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:nY6PzQvvjA2wST5ZuQgGJXmCV6o= sha1:bZdL5txxfQ7KiHi7NzXIBMgqATE= Xref: csiph.com comp.lang.php:14682 Gregor Kofler writes: > Am 2014-12-03 um 16:19 schrieb Christoph M. Becker: >> 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. >>> >>> Catchable Fatal Error: Object of class >>> Symfony\Component\HttpFoundation\File\UploadedFile could not be >>> converted to boolean in >>> /var/www/strbase_client/src/Strbase/ClientBundle/Controller/BatchController.php >>> line 54" >>> >>> Why does the object to boolean conversion in the if condition in line 50 >>> *not* cause an error? >> >> What gets printed when you change line 51 to: >> >> var_dump($file);} >> >> I guess that answers your question. > > > Erm... no. Line 51 is not reached - hence I get precisely the same > output as above. > $file exists and is a UploadedFile instance. > > This works for me: class a {} $b = new a (); if (!$b) { } else { echo '$a is an object!'; var_dump (!$b); } Maybe its an issue related to your specific class? -- Matthew Carter (m@ahungry.com) http://ahungry.com