PHP Flashcards
Who is designed by PHP ?
Rasmus Lerdorf
PHP initial release date ?
1995
What does PHP stand for?
Hypertext Preprocessor
PHP files have a default file extension of
.php
What is/are PHP code editors ?
Adobe Dreamweaver
Notepad
Notepad++
Which of the following correct PHP syntax?
<?php…?>
What is WAMP server ?
Windows Apache MySQL PHP
In PHP, instructions are terminated by using what?
;
What is a correct way to add a comment in PHP?
/…/
How do you write “Hello World” in PHP
echo “Hello World”;
What type specifier is invalid in print f() functions ?
% a
PHP Variable start with which symbol?
$
The PHP syntax is most similar to:
Perl and C
What is the correct way to include the file “header.inc” ?
<?php include “header.inc”; ?>
In PHP what is the difference between include() and require() ?
They are different how they handle failure
To process image what library needed in PHP?
GD Library
In PHP, what function is used to insert content of one php file into another php file before server executes ?
include()
What function is used to redirect a page ?
header()
PHP variables are_____ ?
Multitype variables
How can we check the value of a given variable is a number?
is_numeric()
What variable assignment is ‘by value’ assignment in PHP ?
$value1= $value?
How can we check the value of a given variable is alphanumeric?
ctype_alnum()
How do I check if a given variable is empty?
empty()
Identify the variable scope that is not supported by PHP ?
Hidden variables
What is the correct way to create a function in PHP?
function myFunction()
What is the correct way to open the file “footer.txt” as readable?
fopen(“footer.txt”,”r”);
Which version of PHP introduced Try/catch Exception ?
PHP 5
What PHP function can be used to find files ?
glob()
The left association operator % is used in PHP for ?
bitwise or
In PHP what is the best all-purpose way of comparing two strings ?
Using strcmp()
What will be the value of $var?
$var = 1 / 2;
0.5
What function returns the number of characters in a string variable ?
strlen($variable)
How do you get information from a form when method is “post”?
$_POST[ ];
In php which method is used to get browser properties?
$_SERVER[‘HTTP_USER_AGENT’];
In PHP what gives a string containing PHP script file name in which it is called ?
$_PHP_SELF
Which superglobal variable holds information about headers, paths, and script locations?
$_SERVER
Which type of variables are floating-point numbers, like 3.14159 or 49.1 ?
Doubles
In PHP which method sends input to a script through(via) a URL ?
Get
What is the correct way to add 1 to the $count variable?
$count++;
Which one of these variables has an illegal name?
A) $my_Var
B) $my-Var <=this one
C) $myVar
D) $_myVar
B is the correct answer
Which are compound data type?
Array
and
Objects
Which method acts as a constructor function in a PHP class ?
__construct
How do you create an array in PHP?
$cars = array(“Volvo”, “BMW”, “Toyota”);
How do we access the value of ‘d’ later?
$a = array(
‘a’,
3 => ‘b’,
1 => ‘c’,
‘d’
);
$a[4]
What will be printed?
<?php
$a = array(
null => ‘a’,
true => ‘b’,
false => ‘c’,
0 => ‘d’,
1 => ‘e’,
‘’ => ‘f’
);
echo count($a), “\n”;
?>
3
What will be the output of the following PHP code?
<?php
define(“Hi”,”Hello! How are you ?”);
echo constant(“Hi”);
?>
Hello! How are you ?
Which in-built function will add a value to the end of an array ?
array_push()
Which two predefined variables are used to retrieve information from forms ?
$_GET & $_SET
How to start session in php?
session_start()
What is used to check that a cookie is set or not ?
isset() function
How do you create a cookie in PHP?
setcookie()
In PHP what is not a session function ?
A) session_destroy
B) session_decode
C) session_id
D) session_pw
Correct Answer : Option (D) :
session_pw
In PHP the function setcookie( ) is used to ?
Store data in cookie variable
What is the purpose of $_SESSION[]?
Used to store variables of the current session
What is the default execution time set in set_time_limit()?
30 secs
Which statement about the code below is correct?
<?php
class A {}
class B {}
class C extends A, B {}
?>
class C can not extend both A and B
Which of the following is true about php.ini file ?
A)
The php.ini file is read each time PHP is initialized.
B)
The PHP configuration file, php.ini, is the final and most immediate way to affect the functionality of PHP.
C)
All of the above
D)
None of the above
Correct Answer : Option (C) :
All of the above
Which function returns an array consisting of associative key/value pairs ?
array_count_values()
Which operator is used to check if two values are equal and of same data type?
===
What is the use of explode() in PHP?
Used to split a string by a string
How do I create PHP arrays in a HTML <form>?
<input></input>
In which variable is the users IP address stored?
$REMOTE_ADDR
Which of the following method can be used to create a MySql database using PHP ?
mysql_query()
Which functions is used to get the height of an image :
imagesy()
What is the function file_get_contents() useful for?
read
Which of the following is NOT a valid PHP comparison operator?
&&&
How to determine number of rows returned in result set?
mysqli_num_rows()
Which one of the following function is used to send a e-mail using PHP script ?
mail()
Which function gives us the number of affected entries by a query?
mysqli_affected_rows()
What is the default upload file size in php?
2 MB
Which method can be used to close a MySQL database using PHP ?
mysql_close()
In PHP the error control operator is _______ ?
@
What is the output ?
<?php
define(“x”,”5”);
$x=x+10;
echo x;
?>
5
there’s an issue with the code. The constant “x” is defined with double quotes around its name and value, which is not the correct syntax for defining constants in PHP. It should use single quotes or no quotes at all for both the constant name and value. Here’s the corrected code:
define(“x”, 5);
$x = x + 10;
echo $x;
What is the output.
<?php
$x=array(1,3,2,3,7,8,9,7,3);
$y=array_count_values($x);
echo $y[9];
?>
1
What will be printed ?
if (null === false) {
echo ‘true’;
} else {
echo ‘false’;
}
false
The triple equal sign comparison operator not only checks if the variables are equal in value, but it also confirms that they are of the same type before it returns true or false .
What is the difference between echo and print?
Echo can take multiple parameters where as print cannot
What is the perfect output ?
<?php
$RESULT = 11 + 011 + 0x11;
echo “$RESULT”;
?>
37
$RESULT is a variable where the result of a calculation will be stored. 11 is a decimal number (base 10) and is equal to 11. 011 is an octal number (base 8) because it starts with a leading zero. In octal, 011 is equal to 9 in decimal. 0x11 is a hexadecimal number (base 16) because it starts with "0x." In hexadecimal, 0x11 is equal to 17 in decimal.
Now, let’s calculate the result:
11 (decimal) + 9 (octal) + 17 (hexadecimal) = 37 (decimal)
So, the variable $RESULT holds the value 37.
What is the correct abstract method?
abstract public function write();
What array represents an array with a numeric index?
Numeric Array
In mail($param2, $param2, $param3, $param4), the $param2 contains:
The subject
Which of following function return 1 when output is successful?
print ( )
Which function is used to strip whitespace (or other characters) from the beginning and end of a string?
trim
Which of the following is not true?
PHP applications can not be compiled
If a boolean variable $ alive= 5;
$ alive is true
Which PHP functions accepts any number of parameters?
func_get_args()
Which of following is not a Superglobals in PHP?
$_PUT
What will be the output of the following PHP code?
<?php $a = 5; $b = 5; echo ($a === $b); ?>
1
It assigns the value 5 to a variable named "$a." It assigns the value 5 to another variable named "$b." It then checks if the value of "$a" is exactly the same as the value of "$b" using "===". Finally, it prints (echos) the result of this comparison.
Which of the conditional statements is/are supported by PHP?
i) if statements
ii) if-else statements
iii) if-elseif statements
iv) switch statements
i), ii), iii) and iv)
Which of the looping statements is/are supported by PHP?
i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop
A) i) and ii)
B) i), ii) and iii)
C) i), ii), iii) and iv)
D) None of the above
Correct Answer : Option (C) : i), ii), iii) and iv)
What will be the value of $a and $b after the function call in the following PHP code?
<?php function doSomething( &$arg ) { $return = $arg; $arg += 1; return $return; } $a = 3; $b = doSomething( $a ); ?>
a is 4 and b is 3
The value of $a becomes 4 because it was modified within the doSomething function. The value of $b becomes 3 because it received the original value of $a before the modification due to the return $return; statement.
So, at the end of this code, $a holds 4, and $b holds 3.
If $a = 12 what will be returned when ($a == 12) ?
5
Type Hinting was introduced in which version of PHP?
PHP 5
What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo ‘I am b’;
}
echo ‘I am a’;
}
a();
a();
?>
I am a
when run thru a complier: ERROR!
Parse error: syntax error, unexpected identifier “am”, expecting “,” or “;” in /tmp/1HPOaj7nVx.php on line 8
A function in PHP which starts with __ (double underscore) is known as ___
Magic Function
PHP’s numerically indexed array begin with position ___________
0
Which of the following are correct ways of creating an array?
i) state[0] = “nellore”;
ii) $state[] = array(“nellore”);
iii) $state[0] = “nellore”;
iv) $state = array(“nellore”);
iii) and iv)
Which PHP function will return true if a variable is an array or false if it is not an array?
is_array()
Which in-built function will add a value to the end of an array?
array_push()
What function is used to get the value of the previous element in an array?
prev()
Which function returns an array consisting of associative key/value pairs?
array_count_values()
Which function should we use to sort the array in natural order?
natcasesort()
The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
Encapsulation
Which of the following term originates from the Greek language that means “having multiple forms,” defines OOP’s ability to redefine, a class’s characteristics?
Polymorphism
The practice of creating objects based on predefined classes is often referred to as ______
object instantiation
What can be used to instantiate an object in PHP assuming class name to be Foo
$obj = new foo ();
What is the right way to define a constant?
const
Example:
const PI = ‘3.1415’;
What is the right way to invoke a method?
$object->methodName();
Which of the following is/are the right way to declare a method?
i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }
i) and ii)
Which keyword allows class members (methods and properties) to be used without needing to instantiate a new instance of the class?
static
Which method scope prevents a method from being overridden by a subclass?
Final
PHP recognizes constructors by the name _________
function __construct()
Which one of the following keyword is used to inherit our subclass into a superclass?
extends
Which one of the following is the right way to clone an object?
destinationObject = clone targetObject;
The class from which the child class inherits is called _______
Parent class or Base class
Which method is used to tweak an object’s cloning behavior?
__clone()
Which magic method is used to implement overloading in PHP?
__call
What is the description of Error level E_ERROR?
Fatal run-time error
How many error levels are available in PHP?
16
Say you want to report error concerned about fatal run-time, fatal compile-time error and core error which statement would you use?
error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR
Which of the following statements causes PHP to disregard repeated error messages that occur within the same file and on the same line?
ignore_repeated_errors
Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?
define_syslog_variable()
Which function is responsible for sending a custom message to the system log?
syslog()
Which version added the method getPrevious()?
PHP 5.3
Which one of the following is the right description for the method getMessage()?
Returns the message if it is passed to the constructor
What does SPL stand for?
Standard PHP Library
Which of the following is/are an exception?
i) BadFunctionCallException
ii) BadMethodCallException
iii) LogicException
iv) DomainException
all of them
What filter is used to filter several variables with the same or different filters?
filter_var_array()
What does not describe a validating filter?
Are used to allow or disallow specific characters in a string
[:alpha:] can also be specified as ________
[A-za-z]
POSIX implementation was deprecated in which version of PHP?
PHP 5.3
POSIX stands for _______
Portable Operating System Interface for Unix
What will be the output of the following PHP code?
<?php $text = "this is\tsome text that\nwe might like to parse."; print_r(split("[\n\t]",$text)); ?>
[0] => this is [1] => some text that [2] => we might like to parse.
What will be the output of the following PHP code?
<?php function convertSpace($string) { return str_replace("_", " ", $string); } $string = "Peter_is_a_great_guy!"; echo filter_var($string, FILTER_CALLBACK, array("options"=>"convertSpace")); ?>
Peter is a great guy!
What will be the output of the following PHP code?
<?php $value = 'car'; $result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); ?>
NULL
What will be the output of the following PHP code?
<?php $var=300; $int_options = array("options"=>array ("min_range"=>0, "max_range"=>256)); if (!filter_var($var, FILTER_VALIDATE_INT, $int_options)) echo("Integer is not valid"); else echo("Integer is valid"); ?>
Integer is not valid
What will be the output of the following PHP code?
<?php $num = "123"; if (!filter_var($num, FILTER_VALIDATE_INT)) echo("Integer is not valid"); else echo("Integer is valid"); ?>
Integer is valid
Which among the following is/are not a metacharacter?
i) \a
ii) \A
iii) \b
iv) \B
Only i)
What will be the output of the following PHP code?
<?php $foods = array("pasta", "steak", "fish", "potatoes"); $food = preg_grep("/^s/", $foods); print_r($food); ?>
Array ( [1] => steak )
Which functions will convert a string to all uppercase?
strtoupper()
What will be the output of the following PHP code?
<?php echo str_pad("Salad", 5)." is good."; ?>
Salad is good
Which function can be used to concatenate array elements to form a single delimited string?
implode()
Which function finds the last occurrence of a string, returning its numerical position?
strrpos()
What will be the output of the following PHP code?
<?php $url = "freetimelearn@example.com"; echo ltrim(strstr($url, "@"),"@"); ?>
example.com
The filesize() function returns the file size in _________
bytes
Which PHP function is used to determine a file’s last access time?
fileatime()
Which function is capable of reading a file into a string variable?
file_get_contents()
What function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?
fgetss()
Which one of the following function outputs the contents of a string variable to the specified resource?
fwrite()
Which function is useful when you want to output the executed command result?
system()
Which one of the following function reads a directory into an Array?
scandir()
The date() function returns ___ representation of the current date and/or time.
String
Which one of the following format parameter can be used to identify timezone?
E
Which one of the following function is useful for producing a timestamp based on a given date and time?
mktime()
Which function displays the web page’s most recent modification date?
getlastmod()
What will be the output of the following code? (If say date is 08/10/2018.)
<?php echo "Today is ".date("F d, Y"); ?>
Today is October 08, 2018
Suppose you want to calculate the date 45 days from the present date which one of the following statement will you use?
strtotime(“+45 days”)
Which two predefined variables are used to retrieve information from forms?
$_GET & $_SET
When you use the $_GET variable to collect data, the data is visible to _______
everyone
Which variable is used to collect form data sent with both the GET and POST methods?
$_REQUEST
Which one of the following should not be used while sending passwords or other sensitive information?
GET
To validate an email address, which flag is to be passed to the function filter_var()?
FILTER_VALIDATE_EMAIL
In which authentication method does changing the username or password can be done only by entering the code and making the manual adjustment.
Hard-coding a login pair directly into the script
Which function is used to verify whether a variable contains a value?
isset()
Which of the following variables does PHP use to authenticate a user?
i) $_SERVER[‘PHP_AUTH_USER’].
ii) $_SERVER[‘PHP_AUTH_USERS’].
iii) $_SERVER[‘PHP_AUTH_PU’].
iv) $_SERVER[‘PHP_AUTH_PW’].
i) $_SERVER[‘PHP_AUTH_USER’]
&
iv) $_SERVER[‘PHP_AUTH_PW’].
Which function is used to split a string into a series of substrings, with each string boundary is determined by a specific separator?
explode()
What is one of the most powerful authentication methods?
Data-based authentication
Which directive determines whether PHP scripts on the server can accept file uploads?
file_uploads
Which of the following directive determines the maximum amount of time that a PHP script will spend attempting to parse input before registering a fatal error?
max_input_time
Since which version of PHP was the directive max_file_limit available.
PHP 5.2.12
Which function is used to determine whether a file was uploaded?
is_uploaded_file()
What is the full form of DNS?
Domain Name System
Which of the following statements is used to add an attachment to the mail?
$mimemail->addAttachment(‘attachment.pdf’);
Which one of the following is the very first task executed by a session enabled page?
Check whether a valid session exists
Which directive determines how the session information will be stored?
session.save_handler
If session.use_cookie is set to 0, this results in use of _______
URL rewriting
Neglecting to set which of the following cookie will result in the cookie’s domain being set to the host name of the server which generated it.
session.cookie_domain
Which one of the following function is used to start a session?
session_start()
Which function is used to erase all session variables stored in the current session?
session_unset()
Which one of the following statements should you use to set the session username to Chanti?
$_SESSION[‘username’] = “Chanti”;
Which function effectively deletes all sessions that have expired?
SessionHandler::gc
Which one of the following statements should be used to disable just the fopen(), and file() functions?
disable_functions = fopen, file
Which one of the following method is invoked when an undefined method is called by client code?
__call()
Which method introduced in PHP 5, is invoked just before an object is a garbage collected?
__destruct()
__clone() is run on the ___ object.
copied
Which one of the following is the correct way of declaring a namespace?
namespace my;
Which one of the following statements is true for include_once() and require_once()?
Both do not handle the errors in the same way
Which one of the following functions will you use to check that the class exists before you work with it?
class_exists()
Which one of the following will you use to check the class of an object?
get_class()
If you call a method and it doesn’t exist it’ll cause a problem. To check the method which function will you use?
is_callable()
Which one of the following function should I use to find the parent class of a class?
get_parent_class()
Which class accepts a class name or an object reference and returns an array of interface name?
class_implements()
Object-oriented code tries to minimize dependencies by moving responsibility for handling tasks away from ___ and toward the objects in the system.
client code
_______ code makes change easier because the impact of altering an implementation will be localized to the component being altered.
Orthogonal
Which one of the following is known as the key to object-oriented programming?
Encapsulation
UML stands for?
unified modeling language
In a class diagram the class is divided into three sections, what is displayed in the first section?
Class Name
______ are used in class diagrams to describe the way in which specific elements should be used.
Constraints
+ is the visibility code for?
Public
What will be the output of the following PHP code?
<?php
$color = red;
echo “$color”;
?>
$color
Inheritance in class diagrams is depicted by________
single-headed empty arrow
What will be the output of the following PHP code?
<?php
$color1 = red;
$color2 = green;
echo “$color1”.”$color2”;
?>
ERROR!
Fatal error: Uncaught Error: Undefined constant “red” in /tmp/uVn1YGHHJv.php:4
Stack trace:
#0 {main}
thrown in /tmp/uVn1YGHHJv.php on line 4
What will be the output of the following PHP code?
<?php
$color1 = “red”;
$color2 = “green”;
echo “$color1” + “$color2”;
?>
0
<?php
$color1 = “1”;
$color2 = “1”;
echo “$color1” + “$color2”;
?>
2
What will be the output of the following PHP code?
<?php
$x = 5;
$y = 10;
$z = “$x + $y”;
echo “$z”;
?>
10+5
What will be the output of the following PHP code?
<?php
$x = 3.3;
$y = 2;
echo $x % $y;
?>
1
What will be the output of the following PHP code?
<?php
$x = 4;
$y = 3;
$z = 1;
echo “$x = $x + $y + $z”;
?>
4 = 4 + 3 + 1
What will be the output of the following PHP code?
<?php
$x = 4;
$y = -3;
$z = 11;
echo 4 + $y * $z / $x;
?>
-4.25
What will be the output of the following PHP code?
<?php
$on$e = 1;
$tw$o = 2;
$thre$e = 3;
$fou$r = 4;
echo “$on$e / $tw$o + $thre$e / $fou$r”;
?>
Error
What will be the output of the following PHP code?
<?php
$hello = “Hello World”;
$bye = “Bye”;
echo $hello;”$bye”;
?>
Hello World
What will be the output of the following PHP code?
<?php
$a = “$winner”;
$b = “$looser”;
echo $a, $b;
?>
$looser
What will be the output of the following PHP code?
<?php
$x = 5;
$y = 10;
function fun()
{
$GLOBALS[‘y’] = $GLOBALS[‘x’] + $GLOBALS[‘y’];
}
fun();
echo $y;
?>
15
<?php
function fun()
{
static $x = 0;
echo $x;
$x++;
}
fun();
fun();
fun();
?>
012
What will be the output of the following PHP code?
<?php
$x = 0;
function fun()
{
echo $GLOBALS[‘x’];
$x++;
}
fun();
fun();
fun();
?>
000
What will be the output of the following PHP code?
<?php
$a = 10;
echo ++$a;
echo $a++;
echo $a;
echo ++$a;
?>
11111213
What will be the output of the following PHP code?
<?php
$x = “test”;
$y = “this”;
$z = “also”;
$x .= $y .= $z ;
echo $x;
echo $y;
?>
testthisalsothisalso
What will be the output of the following PHP code?
<?php
$y = 2;
if (**$y == 4)
{
echo $y;
}
?>
error at line2
What will be the output of the following PHP code?
<?php
$y = 2;
if (–$y == 2 || $y xor –$y)
{
echo $y;
}
?>
0
What will be the output of the following PHP code?
<?php
$y = 2;
$w = 4;
$y *= $w /= $y;
echo $y, $w;
?>
42
What is Joomla in PHP?
An open-source CMS (Content Management System)
Can I generate DLL files from PHP scripts like in Perl?
No, you cannot generate DLL (Dynamic Link Library) files directly from PHP scripts like you can in Perl.
In mysql_fetch_array() if two or more columns of the result have the same field names, what action is taken?
the last column will take precedence
In which variable is the users IP address stored?
$REMOTE_ADDR
What is the difference between GET and POST method?
GET displays the form values entered in the URL of the address bar where as POST does not.
What is x+ mode in fopen() used for?
Read/Write. Creates a new file. Returns FALSE and an error if file already exists
Can I run several versions of PHP at the same time?
Yes
Can I have new lines in $subject tag of php’s mail function?
No
What is the use of mysql_pconnect()?
-Used to create a persistant connection to mysql server.
- Used to return an identifier of an existing open connection before opening new connection.
Which function is used to strip whitespace (or other characters) from the beginning and end of a string?
trim
Can we use include (”test.php”) two times in a PHP page “test1.PHP”?
Yes
What is the strpos() function used for?
Search for character within a string
How can I run COM object from remote server ?
like we run local objects
pass the IP of the remote machine as second parameter to the COM constructor.
PHP supports explicit type definition in variable declaration.
False
How do I find out the number of parameters passed into function?
By using func_num_args()
What is PHP heredoc used for?
allows creating multiple lines of string without using quotations
Parent constructors are not called __________ if the child class defines a constructor
implicitly
____________ function in PHP returns a list of response headers sent (or ready to send)
headers_list()
What happens if no file path is given in include() function?
Include_path is made use of
A PHP function cannot be overloaded or redefined
True
How is the setrawcookie function different from the setcookie function?
setrawcookie sets the cookie without URL encoding the value, while setcookie URL encodes the value by defualt
what is the parameter passed to the fgets() function in php to read a single line from a file?
the file pointer to read from
what is the output of the following code?
$i =1;
do{echo$i; $i++;}
while($i<=5);
12345
which keyword is used to declare a class as protected in php?
protected
which keyword is used to pass an object as a reference in php
&
what happens when a form is submitted to a php script that contains two elements with the same name?
VAlue of the second element overwrites the first in specific super global array