Re: RES: [PHP] inexplicable behaviour SOLVED
| From: | PJ | Date: | Mon, 27 Apr 2009 13:21:23 +0000 |
| Subject: | Re: RES: [PHP] inexplicable behaviour SOLVED | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292016@lists.php.net to get a copy of this message | ||
Ford, Mike wrote:
> 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!
>
>
Thanks for the clarification, Mike. In my ignorance, I was under the
impression that the right side of the equation was only for the use of
the left part. How stupid of me. So what I should have been doing was
$Count1 = $Count + 1; right?
Anyway, I don't need that statement anymore as I found the error of my
ways and have corrected it. And behold, the light came forth and it
worked. :-)
> 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
>
>
--
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- pj@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php