PHP Flashcards

1
Q

Who is designed by PHP ?

A

Rasmus Lerdorf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

PHP initial release date ?

A

1995

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does PHP stand for?

A

Hypertext Preprocessor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

PHP files have a default file extension of

A

.php

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is/are PHP code editors ?

A

Adobe Dreamweaver
Notepad
Notepad++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following correct PHP syntax?

A

<?php…?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is WAMP server ?

A

Windows Apache MySQL PHP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In PHP, instructions are terminated by using what?

A

;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a correct way to add a comment in PHP?

A

//

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you write “Hello World” in PHP

A

echo “Hello World”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What type specifier is invalid in print f() functions ?

A

% a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

PHP Variable start with which symbol?

A

$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The PHP syntax is most similar to:

A

Perl and C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the correct way to include the file “header.inc” ?

A

<?php include “header.inc”; ?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In PHP what is the difference between include() and require() ?

A

They are different how they handle failure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

To process image what library needed in PHP?

A

GD Library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In PHP, what function is used to insert content of one php file into another php file before server executes ?

A

include()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What function is used to redirect a page ?

A

header()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

PHP variables are_____ ?

A

Multitype variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How can we check the value of a given variable is a number?

A

is_numeric()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What variable assignment is ‘by value’ assignment in PHP ?

A

$value1= $value?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How can we check the value of a given variable is alphanumeric?

A

ctype_alnum()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do I check if a given variable is empty?

A

empty()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Identify the variable scope that is not supported by PHP ?

A

Hidden variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the correct way to create a function in PHP?
function myFunction()
26
What is the correct way to open the file "footer.txt" as readable?
fopen("footer.txt","r");
27
Which version of PHP introduced Try/catch Exception ?
PHP 5
28
What PHP function can be used to find files ?
glob()
29
The left association operator % is used in PHP for ?
bitwise or
29
In PHP what is the best all-purpose way of comparing two strings ?
Using strcmp()
30
What will be the value of $var? $var = 1 / 2;
0.5
31
What function returns the number of characters in a string variable ?
strlen($variable)
31
How do you get information from a form when method is "post"?
$_POST[ ];
32
In php which method is used to get browser properties?
$_SERVER[‘HTTP_USER_AGENT’];
33
In PHP what gives a string containing PHP script file name in which it is called ?
$_PHP_SELF
34
Which superglobal variable holds information about headers, paths, and script locations?
$_SERVER
34
Which type of variables are floating-point numbers, like 3.14159 or 49.1 ?
Doubles
35
In PHP which method sends input to a script through(via) a URL ?
Get
36
What is the correct way to add 1 to the $count variable?
$count++;
37
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
38
Which are compound data type?
Array and Objects
39
Which method acts as a constructor function in a PHP class ?
__construct
40
How do you create an array in PHP?
$cars = array("Volvo", "BMW", "Toyota");
41
How do we access the value of 'd' later? $a = array( 'a', 3 => 'b', 1 => 'c', 'd' );
$a[4]
42
What will be printed? 'a', true => 'b', false => 'c', 0 => 'd', 1 => 'e', '' => 'f' ); echo count($a), "\n"; ?>
3
43
What will be the output of the following PHP code?
Hello! How are you ?
44
Which in-built function will add a value to the end of an array ?
array_push()
44
Which two predefined variables are used to retrieve information from forms ?
$_GET & $_SET
45
How to start session in php?
session_start()
45
What is used to check that a cookie is set or not ?
isset() function
46
How do you create a cookie in PHP?
setcookie()
47
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
47
In PHP the function setcookie( ) is used to ?
Store data in cookie variable
48
What is the purpose of $_SESSION[]?
Used to store variables of the current session
49
What is the default execution time set in set_time_limit()?
30 secs
50
Which statement about the code below is correct?
class C can not extend both A and B
51
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
52
Which function returns an array consisting of associative key/value pairs ?
array_count_values()
53
Which operator is used to check if two values are equal and of same data type?
===
54
What is the use of explode() in PHP?
Used to split a string by a string
55
How do I create PHP arrays in a HTML
?
56
In which variable is the users IP address stored?
$REMOTE_ADDR
57
Which of the following method can be used to create a MySql database using PHP ?
mysql_query()
57
Which functions is used to get the height of an image :
imagesy()
58
What is the function file_get_contents() useful for?
read
59
Which of the following is NOT a valid PHP comparison operator?
&&&
60
How to determine number of rows returned in result set?
mysqli_num_rows()
61
Which one of the following function is used to send a e-mail using PHP script ?
mail()
62
Which function gives us the number of affected entries by a query?
mysqli_affected_rows()
63
What is the default upload file size in php?
2 MB
64
Which method can be used to close a MySQL database using PHP ?
mysql_close()
65
In PHP the error control operator is _______ ?
@
65
What is the output ?
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;
66
What is the output.
1
67
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 .
68
What is the difference between echo and print?
Echo can take multiple parameters where as print cannot
69
What is the perfect output ?
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.
70
What is the correct abstract method?
abstract public function write();
71
What array represents an array with a numeric index?
Numeric Array
72
In mail($param2, $param2, $param3, $param4), the $param2 contains:
The subject
72
Which of following function return 1 when output is successful?
print ( )
73
Which function is used to strip whitespace (or other characters) from the beginning and end of a string?
trim
74
Which of the following is not true?
PHP applications can not be compiled
74
If a boolean variable $ alive= 5;
$ alive is true
74
Which PHP functions accepts any number of parameters?
func_get_args()
75
Which of following is not a Superglobals in PHP?
$_PUT
76
What will be the output of the following PHP code?
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.
77
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)
78
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)
79
What will be the value of $a and $b after the function call in the following PHP code?
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.
79
If $a = 12 what will be returned when ($a == 12) ?
5
80
Type Hinting was introduced in which version of PHP?
PHP 5
80
What will be the output of the following PHP code?
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
81
A function in PHP which starts with __ (double underscore) is known as ___
Magic Function
82
PHP’s numerically indexed array begin with position ___________
0
83
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)
84
Which PHP function will return true if a variable is an array or false if it is not an array?
is_array()
85
Which in-built function will add a value to the end of an array?
array_push()
86
What function is used to get the value of the previous element in an array?
prev()
87
Which function returns an array consisting of associative key/value pairs?
array_count_values()
88
Which function should we use to sort the array in natural order?
natcasesort()
89
The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
Encapsulation
90
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
91
The practice of creating objects based on predefined classes is often referred to as ______
object instantiation
92
What can be used to instantiate an object in PHP assuming class name to be Foo
$obj = new foo ();
93
What is the right way to define a constant?
const Example: const PI = ‘3.1415’;
94
What is the right way to invoke a method?
$object->methodName();
95
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)
96
Which keyword allows class members (methods and properties) to be used without needing to instantiate a new instance of the class?
static
97
Which method scope prevents a method from being overridden by a subclass?
Final
98
PHP recognizes constructors by the name _________
function __construct()
99
Which one of the following keyword is used to inherit our subclass into a superclass?
extends
100
Which one of the following is the right way to clone an object?
destinationObject = clone targetObject;
101
The class from which the child class inherits is called _______
Parent class or Base class
102
Which method is used to tweak an object’s cloning behavior?
__clone()
103
Which magic method is used to implement overloading in PHP?
__call
104
What is the description of Error level E_ERROR?
Fatal run-time error
105
How many error levels are available in PHP?
16
106
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
107
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
108
Which function initializes the constants necessary for using the openlog(), clodelog(), and syslog() functions?
define_syslog_variable()
109
Which function is responsible for sending a custom message to the system log?
syslog()
110
Which version added the method getPrevious()?
PHP 5.3
111
Which one of the following is the right description for the method getMessage()?
Returns the message if it is passed to the constructor
112
What does SPL stand for?
Standard PHP Library
113
Which of the following is/are an exception? i) BadFunctionCallException ii) BadMethodCallException iii) LogicException iv) DomainException
all of them
114
What filter is used to filter several variables with the same or different filters?
filter_var_array()
115
What does not describe a validating filter?
Are used to allow or disallow specific characters in a string
116
[:alpha:] can also be specified as ________
[A-za-z]
117
POSIX implementation was deprecated in which version of PHP?
PHP 5.3
118
POSIX stands for _______
Portable Operating System Interface for Unix
119
What will be the output of the following PHP code?
[0] => this is [1] => some text that [2] => we might like to parse.
120
What will be the output of the following PHP code? "convertSpace")); ?>
Peter is a great guy!
121
What will be the output of the following PHP code?
NULL
122
What will be the output of the following PHP code? 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
123
What will be the output of the following PHP code?
Integer is valid
124
Which among the following is/are not a metacharacter? i) \a ii) \A iii) \b iv) \B
Only i)
125
What will be the output of the following PHP code?
Array ( [1] => steak )
126
Which functions will convert a string to all uppercase?
strtoupper()
127
What will be the output of the following PHP code?
Salad  is good
128
Which function can be used to concatenate array elements to form a single delimited string?
implode()
129
Which function finds the last occurrence of a string, returning its numerical position?
strrpos()
130
What will be the output of the following PHP code?
example.com
131
The filesize() function returns the file size in _________
bytes
132
Which PHP function is used to determine a file’s last access time?
fileatime()
133
Which function is capable of reading a file into a string variable?
file_get_contents()
134
What function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?
fgetss()
135
Which one of the following function outputs the contents of a string variable to the specified resource?
fwrite()
136
Which function is useful when you want to output the executed command result?
system()
137
Which one of the following function reads a directory into an Array?
scandir()
138
The date() function returns ___ representation of the current date and/or time.
String
139
Which one of the following format parameter can be used to identify timezone?
E
140
Which one of the following function is useful for producing a timestamp based on a given date and time?
mktime()
141
Which function displays the web page’s most recent modification date?
getlastmod()
142
What will be the output of the following code? (If say date is 08/10/2018.)
Today is October 08, 2018
143
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”)
144
Which two predefined variables are used to retrieve information from forms?
$_GET & $_SET
145
When you use the $_GET variable to collect data, the data is visible to _______
everyone
146
Which variable is used to collect form data sent with both the GET and POST methods?
$_REQUEST
147
Which one of the following should not be used while sending passwords or other sensitive information?
GET
148
To validate an email address, which flag is to be passed to the function filter_var()?
FILTER_VALIDATE_EMAIL
149
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
149
Which function is used to verify whether a variable contains a value?
isset()
149
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'].
150
Which function is used to split a string into a series of substrings, with each string boundary is determined by a specific separator?
explode()
151
What is one of the most powerful authentication methods?
Data-based authentication
152
Which directive determines whether PHP scripts on the server can accept file uploads?
file_uploads
153
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
154
Since which version of PHP was the directive max_file_limit available.
PHP 5.2.12
155
Which function is used to determine whether a file was uploaded?
is_uploaded_file()
156
What is the full form of DNS?
Domain Name System
157
Which of the following statements is used to add an attachment to the mail?
$mimemail->addAttachment(‘attachment.pdf’);
158
Which one of the following is the very first task executed by a session enabled page?
Check whether a valid session exists
159
Which directive determines how the session information will be stored?
session.save_handler
160
If session.use_cookie is set to 0, this results in use of _______
URL rewriting
161
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
162
Which one of the following function is used to start a session?
session_start()
163
Which function is used to erase all session variables stored in the current session?
session_unset()
164
Which one of the following statements should you use to set the session username to Chanti?
$_SESSION[‘username’] = “Chanti”;
165
Which function effectively deletes all sessions that have expired?
SessionHandler::gc
166
Which one of the following statements should be used to disable just the fopen(), and file() functions?
disable_functions = fopen, file
167
Which one of the following method is invoked when an undefined method is called by client code?
__call()
168
Which method introduced in PHP 5, is invoked just before an object is a garbage collected?
__destruct()
169
__clone() is run on the ___ object.
copied
169
Which one of the following is the correct way of declaring a namespace?
namespace my;
170
Which one of the following statements is true for include_once() and require_once()?
Both do not handle the errors in the same way
171
Which one of the following functions will you use to check that the class exists before you work with it?
class_exists()
172
Which one of the following will you use to check the class of an object?
get_class()
173
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()
174
Which one of the following function should I use to find the parent class of a class?
get_parent_class()
175
Which class accepts a class name or an object reference and returns an array of interface name?
class_implements()
176
Object-oriented code tries to minimize dependencies by moving responsibility for handling tasks away from ___ and toward the objects in the system.
client code
176
_______ code makes change easier because the impact of altering an implementation will be localized to the component being altered.
Orthogonal
177
Which one of the following is known as the key to object-oriented programming?
Encapsulation
178
UML stands for?
unified modeling language
179
In a class diagram the class is divided into three sections, what is displayed in the first section?
Class Name
180
______ are used in class diagrams to describe the way in which specific elements should be used.
Constraints
181
+ is the visibility code for?
Public
182
What will be the output of the following PHP code?
$color
182
Inheritance in class diagrams is depicted by________
single-headed empty arrow
183
What will be the output of the following PHP code?
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
184
What will be the output of the following PHP code?
0
185
2
186
What will be the output of the following PHP code?
10+5
187
What will be the output of the following PHP code?
1
188
What will be the output of the following PHP code?
4 = 4 + 3 + 1
189
What will be the output of the following PHP code?
-4.25
190
What will be the output of the following PHP code?
Error
191
What will be the output of the following PHP code?
Hello World
192
What will be the output of the following PHP code?
$looser
193
What will be the output of the following PHP code?
15
194
012
194
What will be the output of the following PHP code?
000
195
What will be the output of the following PHP code?
11111213
196
What will be the output of the following PHP code?
testthisalsothisalso
197
What will be the output of the following PHP code?
error at line2
197
What will be the output of the following PHP code?
0
198
What will be the output of the following PHP code?
42
199
What is Joomla in PHP?
An open-source CMS (Content Management System)
200
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.
201
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
202
In which variable is the users IP address stored?
$REMOTE_ADDR
203
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.
204
What is x+ mode in fopen() used for?
Read/Write. Creates a new file. Returns FALSE and an error if file already exists
205
Can I run several versions of PHP at the same time?
Yes
206
Can I have new lines in $subject tag of php's mail function?
No
207
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.
208
Which function is used to strip whitespace (or other characters) from the beginning and end of a string?
trim
209
Can we use include (”test.php”) two times in a PHP page “test1.PHP”?
Yes
210
What is the strpos() function used for?
Search for character within a string
211
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.
212
PHP supports explicit type definition in variable declaration.
False
213
How do I find out the number of parameters passed into function?
By using func_num_args()
214
What is PHP heredoc used for?
allows creating multiple lines of string without using quotations
215
Parent constructors are not called __________ if the child class defines a constructor
implicitly
216
____________ function in PHP returns a list of response headers sent (or ready to send)
headers_list()
217
What happens if no file path is given in include() function?
Include_path is made use of
218
A PHP function cannot be overloaded or redefined
True
219
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
220
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
221
what is the output of the following code? $i =1; do{echo$i; $i++;} while($i<=5);
12345
222
which keyword is used to declare a class as protected in php?
protected
223
which keyword is used to pass an object as a reference in php
&
224
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