RE: RES: [PHP] inexplicable behaviour SOLVED
| From: | Ford, Mike | Date: | Mon, 27 Apr 2009 08:00:20 +0000 |
| Subject: | RE: RES: [PHP] inexplicable behaviour SOLVED | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-292009@lists.php.net to get a copy of this message | ||
On 26 April 2009 22:59, PJ advised:
> kranthi wrote:
>> if $Count1 is never referenced after this, then certainly this
>> assignment operation is redundent. but assignment is not the ONLY
>> operation of this statement. if u hav not noticed a post increment
>> operator has been used which will affect the value of $Count as well,
>> and this operation is required for the script to work.
>>
>> the script should work even if u replace
>> $Count1 = $Count++;
>> with
>> $Count++;
>>
>> Kranthi.
>>
>>
> Not quite, since that would change the $Count variable and
> that is used
> leater in the code.
Um -- I must be missing something here, because those two statements
have exactly the same effect on $Count, incrementing it by one (and you
said the first statement fixed your problem, so logically the second one
must too).
In fact, because you've used a post-increment, the statement
$Count1 = $Count++;
ends up with $Count == $Count1+1, and $Count1 being the original value
of $Count!!
This whole scenario smacks to me of a classic "off-by-one" error --
either $Count actually *needs* to be one greater than the value you
first thought of, or some other value you are comparing it to should be
one smaller than it actually is.
Cheers!
Mike
--
Mike Ford, Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus,
Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 812 4730
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm