Page 1 of 1
what is "int"?
Posted: Tue Sep 21, 2004 3:29 pm
by Calipoop
I'm reading a book that keeps sticking an "int" in front of functions, e.g.
Code: Select all
<?php
int fseek(int fp, int offset);
?>
is the int just a temp variable or something? can't find anything about int in the index or the web...
Thanks for your help...!
Posted: Tue Sep 21, 2004 3:43 pm
by magicrobotmonkey
are you sure its a php book? java does that as it has tighter typing than php - "int" means integer, "String" string and so forth
Posted: Tue Sep 21, 2004 3:45 pm
by Calipoop
it's definitely a php book - "Professional PHP Programing"
I think it might have been for php 3
Is it safe to just ignore the "int"? does the code example above still make sense without it?
Re: what is "int"?
Posted: Tue Sep 21, 2004 3:50 pm
by patrikG
Calipoop wrote:I'm reading a book that keeps sticking an "int" in front of functions, e.g.
Code: Select all
<?php
int fseek(int fp, int offset);
?>
is the int just a temp variable or something? can't find anything about int in the index or the web...
Thanks for your help...!
That's PHP5 - you can force types on parameters of methods. In this case, the two parameters (fp and offset) of the class-method fseek() need to be of type integer. The methods itself will return an integer "int fseek(...)".
Posted: Tue Sep 21, 2004 6:31 pm
by d_d
It's telling you the types the function returns and accepts.
In this case the function returns an int, and requires two parameters fp and offset which are both ints.
php docs on fseek
http://uk2.php.net/manual/en/function.fseek.php
php docs on int type
http://www.php.net/manual/en/language.types.integer.php
Posted: Tue Sep 21, 2004 7:11 pm
by Calipoop
yeah you're right d_d - that makes sense with what the book is saying. Thanks
Re: what is "int"?
Posted: Wed Sep 22, 2004 8:56 am
by m3mn0n
Yeah indeed that is what I thought too.
I see a lot of programmers, myself included, who leave comments with int, string, boolean, etc within the function parameters just to indicate to any other coder who reads the function that, that is the type of variable that needs to be inserted into the function.
And the adding int, string, boolean, etc in front of the function name indicates the type of variable the fuction returns.
But don't forget that adding "int" or "string" infront of a variable can also change the variable type, too.
