/    Sign up×
Community /Pin to ProfileBookmark

Is Not All Inside Single Quotes String In PHP ?

Folks,

In PHP, anything inside single quotes is a string. Right ?

Example 1:

““
$type = gettype($_GET[‘page_no’]);

if(ISSET($_GET[‘page_no’]) && $type != ‘integer’)
{
echo ‘5a. Page Number is not INT!’;
}
““

The above code should be checking for the string ‘integer’ in the variable value $type. Right ?
So how come it’s checking for the value’s data type ? I can understand it checking for data type if the string word was inside double quotes.
What is the solution to this mystery ?

QUESTION 2:
Need to check if the value of $type is a number or not.
Look at these 2 examples. On one I use single equal sign while on the other double.
Which one is invalid and why. Answer that. It is important.
And yes, I know the differences between single quotes, double quotes, single equal sign, double equal sign and triple equal sign in PHP.

https://stackoverflow.com/questions/2063480/the-3-different-equals

https://stackoverflow.com/questions/7191626/isset-and-empty-what-to-use

Should not both these following examples be TRUE where one checks if the $type variable has been assigned or not while the other example compares if the $type variable is INT or not ?
In my test, both seem to be showing that $type holds an INT value. Or did I misread the test result ?
Test both exames in your browser and tell me what you figure.

Example 2a:

““
$type = gettype($_GET[‘page_no’]);
if(ISSET($_GET[‘page_no’]) && $type !== “integer”)
{
echo ‘5b. Page Number is not INT!’;
}
““

Example 2b:

““
$type = gettype($_GET[‘page_no’]);
if(ISSET($_GET[‘page_no’]) && $type != “integer”)
{
echo ‘5c. Page Number is not INT!’;
}
““

QUESTiON 3:
Back to single quotes again.
Can you tell me what PHP is doing on the first example and what on the second ?

Example 3a:

““
$type = gettype($_GET[‘page_no’]);
if(ISSET($_GET[‘page_no’]) && $type !== “integer”)
{
echo ‘5b. Page Number is not INT!’;
}
““

Example 3b:

““
$type = gettype($_GET[‘page_no’]);
if(ISSET($_GET[‘page_no’]) && $type != “integer”)
{
echo ‘5c. Page Number is not INT!’;
““

Kindly provide your answers matching my questions numbers. Will be easy for me to understand your answers.

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 12.2021 — Every $_GET element will have a type of string. E.g. /test.php?foo=1 will result in $_GET['foo'] being the string "1", not the integer 1. See your other post for my example of using a regular expression (in a preg_match()) to determine if a string is essentially an integer.
Copy linkTweet thisAlerts:
@bethgradeJan 13.2021 — Having your own website is not enough to run a successful business, as the vast majority of customers use mobile devices. It is optimal to offer them a branded application in which it will be convenient to order a service, track cargo, and manage transport movements. In this article https://merehead.com/blog/much-cost-develop-app-logistic-business/ you'll learn application will be no less relevant for employees.
Copy linkTweet thisAlerts:
@developer_webauthorJan 13.2021 — @NogDog#1626726

I don't remember which thread it was.

Folk at stackoverflow.com also told me $_GET value is string.

On my test, following outputs page number as string.

http://localhost:8080/gettype_notes.php?page=1


$page = $_GET['page'];
echo gettype($page) . "<br>";

×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...