On Fri, 2003-07-04 at 13:13, Rasmus Lerdorf wrote:
> On Fri, 4 Jul 2003, Robert Cummings wrote:
> 
> > On Fri, 2003-07-04 at 12:44, Rasmus Lerdorf wrote:
> > > The difference is that you are getting a string from the file and not
> > > casting it to an integer.  You could also have fixed it by doing:
> > >
> > >   $counter = (int) fread(...);
> >
> > The cast isn't necessary, PHP happily transforms it for him when he
> > applies the ++ operator.
> 
> ;)  You are sure about that right?  Or else you wouldn't have posted this
> to 1000's of people.

I am absolutely sure of thus since I cut and pasted the original problem
code to a shell script to test. This was before I noticed the answer
mentioning the closing if block had already been posted. 

> 
> So what do you think this will output?
> 
>     $a = "123\n";
>     $a++;
>     echo $a;
> 
> Try it.

Undoubtedly the above will work as we both know, the output will be
"123"; however, if you look at the original code in question, there is
no "\n" tailing the output written to the counter file and thus the
increment works fine (unless of course when he created the file to begin
he had a newline - something I did not do in my test :)

Cheers,
Rob.
-- 
.---------------------------------------------.
| Worlds of Carnage - http://www.wocmud.org   |
:---------------------------------------------:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.    |
`---------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to