what is "int"?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Calipoop
Forum Newbie
Posts: 24
Joined: Fri Sep 17, 2004 6:06 pm
Location: Los Angeles, CA

what is "int"?

Post 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...!
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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
Calipoop
Forum Newbie
Posts: 24
Joined: Fri Sep 17, 2004 6:06 pm
Location: Los Angeles, CA

Post 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?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Re: what is "int"?

Post 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(...)".
d_d
Forum Commoner
Posts: 33
Joined: Wed Jul 07, 2004 4:56 pm
Location: UK

Post 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
Calipoop
Forum Newbie
Posts: 24
Joined: Fri Sep 17, 2004 6:06 pm
Location: Los Angeles, CA

Post by Calipoop »

yeah you're right d_d - that makes sense with what the book is saying. Thanks
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Re: what is "int"?

Post 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. :wink:
Post Reply