Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrob111
8,379 Pointswhat does INT mean?
I'm looking at the PHP manual for filter_input function. http://php.net/manual/en/function.filter-input.php
When looking at the description/structure of the function does the "int" stand for integer?
If so how does this make sense? I mean when you look at the $type options from the link above those aren't integers.
mixed filter_input ( int $type , string $variable_name [, int $filter = FILTER_DEFAULT [, mixed $options ]] )
3 Answers
Simon Coates
28,694 PointsThey're constants. You use the word, but the value underneath is an int. To demonstrate:
<?php
echo INPUT_GET;
echo INPUT_POST;
echo INPUT_COOKIE;
?>
outputs 1, 0, and 2
Alex Arzamendi
10,042 Pointsint for an integer value, a numerical value(in simple terms) which does not have a floating point value such as 1.1 and such. The int serves to specify that the function expects a numerical value, then a string etc etc
Serhii Lihus
6,352 PointsHi there Rob!
Yes, int is a shorthand for integer. But do not confuse it with integer type like in pascal language as for example. Or other old programming languages :)
So, lets return to the question. I will take this function as an example.
In this function there are two required parameters and two optional.
First two are: int $type and string $variable_name. According to this, you need to pass one integer value and one string value. And that will be enough for function to work properly and output the result.
What you see in square brackets are optional values. You can simply skip them. Or you can initialize them.
int $filter = FILTER_DEFAULT - in this case you need to pass constant (as it was mentioned previously). This constant holds integer value like 0, 1, 2 ... etc. Same is for first parameter(list of constants that you can pass is defined in function description).
mixed $options - mixed means any type. But only those types which are described for parameter in function description.
For this parameter it is array and bitwise disjunction
Here is the a bit improved example from php.net(taken from comments in function description link):
// in this case it take input from get parameter in get request
// http://site.com/index.php?priority=6
// but it is wiser to check if this parameter holds something and exist ...
if(!empty($_GET['priority']))
{
$options=array('options'=>array('default'=>5, 'min_range'=>0, 'max_range'=>9));
$priority=filter_input(INPUT_GET, 'priority', FILTER_VALIDATE_INT, $options);
// INPUT_GET - is a constant which holds integer value 1
// 'priority' - is the parameter name from query string (which is string)
// FILTER_VALIDATE_INT - is also a constant which holds integer value
// $option - in this case is array value
echo $priority;
}
Additional info: Here is the link that might help you php types
Hope that this will explain few things.
Best regards.
rob111
8,379 Pointsrob111
8,379 PointsThat makes sense now. Just a little confusing because it's not obvious that it gets converted to an integer. I guess you just have to assume that's what is meant because it's not explicitly mentioned on the page.
Can you use an integer number instead of the words? I guess you would have to memorize which number represents which words so may not be practical, but just curious if it can work like that instead.
Simon Coates
28,694 PointsSimon Coates
28,694 PointsThe constant is provided to let you use the name. An integer should work.