FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » strange behaviour in assignment expr.
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
strange behaviour in assignment expr. [message #172848] Sat, 05 March 2011 13:02 Go to next message
Marc van Lieshout is currently offline  Marc van Lieshout
Messages: 10
Registered: March 2011
Karma: 0
Junior Member
I try to read in a source file, line by line, within a loop

This works:

$text = fgets($fh);
if ($text === false)
break;

This doesn't, and always breaks on the first line:

if (($text = fgets($fh)) === false)
break;

What's wrong with that? Am I missing something?
Re: strange behaviour in assignment expr. [message #172849 is a reply to message #172848] Sat, 05 March 2011 13:20 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/5/2011 8:02 AM, Marc van Lieshout wrote:
> I try to read in a source file, line by line, within a loop
>
> This works:
>
> $text = fgets($fh);
> if ($text === false)
> break;
>
> This doesn't, and always breaks on the first line:
>
> if (($text = fgets($fh)) === false)
> break;
>
> What's wrong with that? Am I missing something?

It should work. Check your code again. I suspect you may be using
"==", which will break on an empty string, instead of "===", which will not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: strange behaviour in assignment expr. [message #172850 is a reply to message #172849] Sat, 05 March 2011 13:29 Go to previous messageGo to next message
Marc van Lieshout is currently offline  Marc van Lieshout
Messages: 10
Registered: March 2011
Karma: 0
Junior Member
On 05-03-11 14:20, Jerry Stuckle wrote:
> On 3/5/2011 8:02 AM, Marc van Lieshout wrote:
>> I try to read in a source file, line by line, within a loop
>>
>> This works:
>>
>> $text = fgets($fh);
>> if ($text === false)
>> break;
>>
>> This doesn't, and always breaks on the first line:
>>
>> if (($text = fgets($fh)) === false)
>> break;
>>
>> What's wrong with that? Am I missing something?
>
> It should work. Check your code again. I suspect you may be using
> "==", which will break on an empty string, instead of "===", which
> will not.
>
No, I copypasted. There are three = there.
Re: strange behaviour in assignment expr. [message #172851 is a reply to message #172849] Sat, 05 March 2011 13:33 Go to previous message
Marc van Lieshout is currently offline  Marc van Lieshout
Messages: 10
Registered: March 2011
Karma: 0
Junior Member
On 05-03-11 14:20, Jerry Stuckle wrote:
> On 3/5/2011 8:02 AM, Marc van Lieshout wrote:
>> I try to read in a source file, line by line, within a loop
>>
>> This works:
>>
>> $text = fgets($fh);
>> if ($text === false)
>> break;
>>
>> This doesn't, and always breaks on the first line:
>>
>> if (($text = fgets($fh)) === false)
>> break;
>>
>> What's wrong with that? Am I missing something?
>
> It should work. Check your code again. I suspect you may be using
> "==", which will break on an empty string, instead of "===", which
> will not.
>
*blush* -- wrong source.
It works. Sorry for bothering.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: [ANN]VTD-XML 2.10
Next Topic: having trouble using gd imageline in foreach loop
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 00:58:16 GMT 2024

Total time taken to generate the page: 0.02244 seconds