strange behaviour in assignment expr. [message #172848] |
Sat, 05 March 2011 13:02 |
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 |
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 |
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 |
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.
|
|
|