PHP Interview Questions with 100%
CorrecT Answers
PHP does a good job of automatically converting types from one to another when
necessary.
PHP variables are Perl-like.
What are the different types of PHP variables? - ANSWER PHP has a total of eight
data types which we use to construct our variables −
Integers − are whole numbers, without a decimal point, like 4195.
Doubles − are floating-point numbers, like 3.14159 or 49.1.
Booleans − have only two possible values either true or false.
NULL − is a special type that only has one value: NULL.
Strings − are sequences of characters, like 'PHP supports string operations.'
Arrays − are named and indexed collections of other values.
,Objects − are instances of programmer-defined classes, which can package up both
other kinds of values and functions that are specific to the class.
Resources − are special variables that hold references to resources external to PHP
(such as database connections).
What are rules for naming a PHP variable? - ANSWER Rules for naming a variable
are following −
Variable names must begin with a letter or underscore character.
A variable name can consist of numbers, letters, underscores but you cannot
use characters like + , - , % , ( , ) . & , etc
What are the rules for determine the "truth" of any value not already of the Boolean
type? - ANSWER Here are the rules for determine the "truth" of any value not already
of the Boolean type −
If the value is a number, it is false if exactly equal to zero and true otherwise.
If the value is a string, it is false if the string is empty (has zero characters) or is the
string "0", and is true otherwise.
Values of type NULL are always false.
If the value is an array, it is false if it contains no other values, and it is true
otherwise. For an object, containing a value means having a member variable that
has been assigned a value.
, Valid resources are true (although some functions that return resources when they
are successful will return FALSE when unsuccessful).
Don't use double as Booleans.
What is NULL? - ANSWER NULL is a special type that only has one value: NULL.
The special constant NULL is capitalized by convention, but actually it is case insensitive
A variable that has been assigned NULL has the following properties:
It evaluates to FALSE in a Boolean context.
It returns FALSE when tested with IsSet() function.
How will you define a constant in PHP? - ANSWER To define a constant you have to
use define() function and to retrieve the value of a constant, you have to simply
specifying its name. Unlike with variables, you do not need to have a constant with a
$.
What is the purpose of constant() function? - ANSWER this function will return the
value of the constant. This is useful when you want to retrieve value of a constant, but
you do not know its name
Only scalar data (boolean, integer, float and string) can be contained in constants.
What are the differences between PHP constants and variables? - ANSWER There is no
need to write a dollar sign ($) before a constant, where as in Variable one has to write a
dollar sign.
CorrecT Answers
PHP does a good job of automatically converting types from one to another when
necessary.
PHP variables are Perl-like.
What are the different types of PHP variables? - ANSWER PHP has a total of eight
data types which we use to construct our variables −
Integers − are whole numbers, without a decimal point, like 4195.
Doubles − are floating-point numbers, like 3.14159 or 49.1.
Booleans − have only two possible values either true or false.
NULL − is a special type that only has one value: NULL.
Strings − are sequences of characters, like 'PHP supports string operations.'
Arrays − are named and indexed collections of other values.
,Objects − are instances of programmer-defined classes, which can package up both
other kinds of values and functions that are specific to the class.
Resources − are special variables that hold references to resources external to PHP
(such as database connections).
What are rules for naming a PHP variable? - ANSWER Rules for naming a variable
are following −
Variable names must begin with a letter or underscore character.
A variable name can consist of numbers, letters, underscores but you cannot
use characters like + , - , % , ( , ) . & , etc
What are the rules for determine the "truth" of any value not already of the Boolean
type? - ANSWER Here are the rules for determine the "truth" of any value not already
of the Boolean type −
If the value is a number, it is false if exactly equal to zero and true otherwise.
If the value is a string, it is false if the string is empty (has zero characters) or is the
string "0", and is true otherwise.
Values of type NULL are always false.
If the value is an array, it is false if it contains no other values, and it is true
otherwise. For an object, containing a value means having a member variable that
has been assigned a value.
, Valid resources are true (although some functions that return resources when they
are successful will return FALSE when unsuccessful).
Don't use double as Booleans.
What is NULL? - ANSWER NULL is a special type that only has one value: NULL.
The special constant NULL is capitalized by convention, but actually it is case insensitive
A variable that has been assigned NULL has the following properties:
It evaluates to FALSE in a Boolean context.
It returns FALSE when tested with IsSet() function.
How will you define a constant in PHP? - ANSWER To define a constant you have to
use define() function and to retrieve the value of a constant, you have to simply
specifying its name. Unlike with variables, you do not need to have a constant with a
$.
What is the purpose of constant() function? - ANSWER this function will return the
value of the constant. This is useful when you want to retrieve value of a constant, but
you do not know its name
Only scalar data (boolean, integer, float and string) can be contained in constants.
What are the differences between PHP constants and variables? - ANSWER There is no
need to write a dollar sign ($) before a constant, where as in Variable one has to write a
dollar sign.