Php Objective Questions for written test exams all

Question 1
What will the following script output?


$x = 3 - 5 % 3;

echo $x;


A. 2

B. 1

C. Null

D. True

E. 3
View Answers
Question 2
View Answers
Question 3
View Answers
Question 4
View Answers
Question 5
When serializing and unserializing an object, which of the following precautions

should you keep in mind? (Choose two)

A. Always escape member properties that contain user input.

B. If the object contains resource variables, use magic functions to restore the

resources upon unserialization.

C. Use the magic functions to only save what is necessary.

D. Always use a transaction when saving the information to a database.

E. If the object contains resource variables, it cannot be serialized without first

destroying and releasing its resources.
View Answers
Question 6
What will the following script output?



class a


var $c;

function a()


$this->c = 10;



class b extends a


function print_a()


echo $this->c;



$b = new b;



A. Nothing

B. An error because b does not have a constructor

C. 10


E. False
View Answers
Question 7
Is it possible to pass data from PHP to JavaScript?

A. No, because PHP is server-side, and JavaScript is client-side.

B. No, because PHP is a loosely typed language.

C. Yes, because JavaScript executes before PHP.

D. Yes, because PHP can generate valid JavaScript
View Answers
Question 8
Is it possible to pass data from JavaScript to PHP?

A. Yes, but not without sending another HTTP request.

B. Yes, because PHP executes before JavaScript.

C. No, because JavaScript is server-side, and PHP is client-side.

D. No, because JavaScript executes before PHP.
View Answers
Question 9
Which types of form elements can be excluded from the HTTP request?

A. text, radio, and check box

B. text, submit, and hidden

C. submit and hidden

D. radio and check box
View Answers
Question 10
When processing the form, what is the difference between a hidden form element

and a nonhidden one, such as a text box?

A. The hidden form element does not have a name.

B. There is no difference.

C. The hidden form element does not have a value.

D. The hidden form element is excluded from the request.
View Answers
Question 11
Which of the following form element names can be used to create an array in


A. foo

B. [foo]

C. foo[]

D. foo[bar]
View Answers
Question 12
When an expiration date is given in a Set-Cookie header, what is the resulting

behavior in subsequent requests?

A. If the expiration date has expired, the cookie is not included.

B. The behavior is the same; the expiration date is included in the Cookie

header, and you can access this information in the $_COOKIE superglobal


C. The cookie persists in memory until the browser is closed.

D. The cookie is deleted and therefore not included in subsequent requests.
View Answers
Question 13
If you set a cookie with either setcookie() or header(), you can immediately

check to see whether the client accepted it.

A. True, you can check the $_COOKIE superglobal array to see if it contains the

value you set.

B. True, but only if register_globals is enabled.

C. False, you can only use setcookie() if you need to test for acceptance.

Using header() does not work.

D. False, you must wait until you receive another HTTP request to determine

whether it includes the Cookie header.
View Answers
Question 14
Why must you call session_start() prior to any output?

A. Because it is easy to forget if not placed at the top of your scripts.

B. Because you can no longer access the session data store after there has been


C. Because session_start() sets some HTTP headers.

D. Because calling session_start() causes the HTTP headers to be sent.
View Answers
Question 15
View Answers
Question 16
Which of the following functions allows you to store session data in a database?

A. session_start();

B. session_set_save_handler();

C. mysql_query();

D. You cannot store session data in a database.
View Answers
Question 17
Which of the following types can be used as an array key? (Select three.)

A. Integer

B. Floating-point

C. Array

D. Object

E. Boolean
View Answers
Question 18
Which of the following functions can be used to sort an array by its keys in

descending order?

A. sort

B. rsort

C. ksort

D. krsort

E. reverse_sort
View Answers
Question 19
View Answers
Question 20
View Answers
Question 21
View Answers
Question 22
Which of the following functions is most efficient for substituting fixed patterns in


A. preg_replace()

B. str_replace()

C. str_ireplace()

D. substr_replace()
View Answers
Question 23
View Answers
Question 24
View Answers
Question 25
View Answers
Question 26
Which of the following can be used to determine if a file is readable?

A. stat()

B. is_readable()

C. filetype()

D. fileowner()

E. finfo()
View Answers
Question 27
Specifying the LOCK_NB flag to flock() instructs PHP to

A. Return immediately if someone else is holding the lock.

B. Block indefinitely until the lock is available.

C. Block for a number of seconds dictated by the php.ini setting

flock.max_wait or until the lock is available.

D. Immediately take control of the lock from its current holder.
View Answers
Question 28
If you have an open file resource, you can read data from it one line at a time with

the _____ function.
View Answers
Question 29
Which of the following functions require an open file resource?

A. fgets()

B. fopen()

C. filemtime()

D. rewind()

E. reset()
View Answers
Question 30
Which of the following sentences are incorrect?

A. date() returns the current UNIX datestamp.

B. date() returns a formatted date string.

C. date() requires a time stamp to be passed to it.

D. date() returns a date array.

View Answers
Question 31
The ________ function will return the current UNIX time stamp.

View Answers
Question 32
View Answers
Question 33
The PHP date functions are only guaranteed to work for dates after _____.

A. January 1, 1970 00:00:00

B. January 1, 1900 00:00:00

C. January 1, 1963 00:00:00

D. January 18, 2038 22:14:07
View Answers
Question 34
View Answers
Question 35
View Answers
Question 36
View Answers
Question 37
View Answers
Question 38
View Answers
Question 39
View Answers
Question 40
Which of the following is not an aggregate function?





View Answers
Question 41
In the following query, how will the resultset be sorted?

Select * from my_table order by column_a desc, column_b, column_c

A. By column_a in descending order, by column_b in descending order, and,

finally, by column_c.

B. By column_a, column_b, and column_c, all in descending order.

C. By column_a, column_b, and column_c, all in ascending order.

D. By column_a.Any rows in which column_b has the same value will then be

resorted by column_c in descending order.

E. By column_a in descending order.Any rows in which column_a has the

same value will then be ordered by column_b in ascending order.Any rows

in which both column_a and column_b have the same value will be further

sorted by column_c in ascending order.
View Answers
Question 42
How is a transaction terminated so that the changes made during its course are




C. By terminating the connection without completing the transaction


View Answers
Question 43
View Answers
Question 44
View Answers
Question 45
View Answers
Question 46
View Answers
Question 47
View Answers
Question 48
View Answers
Question 49
Which of the following data filtering methods can be described as a whitelist


A. Make sure that a username does not contain backticks or angled brackets.

B. Only allow alphanumerics and underscores in a username.

C. Pass all incoming data through strip_tags().

D. Use htmlentities() to escape potentially malicious characters.
View Answers
Question 50
With register_globals enabled, which of the following practices is particularly


A. Initialize all variables.

B. Filter all foreign data.

C. Escape all data used in SQL statements.

D. Escape all data prior to output.
View Answers
Question 51
What are the two most important practices to mitigate the risk of an SQL injection


A. Disabling register_globals and enabling safe_mode.

B. Enabling safe_mode and filtering any data used in the construction of the

SQL statement.

C. Filtering and escaping any data used in the construction of the SQL statement.

D. Disabling register_globals and escaping any data used in the construction

of the SQL statement.
View Answers
Question 52
View Answers
Question 53
View Answers
Question 54
View Answers
Question 55
When is cross-site scripting a heightened risk?

A. When storing data submitted by the user.

B. When displaying foreign data.

C. When executing a shell command.

D. When opening a remote URL.
View Answers
Question 56
Which of the following functions can be used to escape data such that it can be

displayed without altering the appearance of the original data?

A. htmlspecialchars()

B. addslashes()

C. escapeshellargs()

D. urlencode()
View Answers
Question 57
What is the purpose of the open_basedir directive?

A. To indicate the directory that include() calls will use as a base.

B. To restrict file open access to a specific directory.

C. To set the working directory.

D. To allow additional file open access than that granted by safe_mode.
View Answers
Question 58
View Answers
Question 59
View Answers
Question 60
View Answers
Question 61
You are in a team of developers working on a number of different business applications.

Your project manager tells you that in two weeks another three PHP

developers will join the team and that you have to ensure that they will be ready

to dive in to the current PHP code without problems.What could you do?

A. Write proper end user documentation on how to use the web front end.

B. Write proper end user documentation and generate proper PHPDoc comments

inside the code to get an API documentation.

C. The absence of documentation will actually encourage the new developers

to delve more deeply into the code.
View Answers
Question 62
View Answers
Question 63
Which of the following strings are not valid modes for the fopen() function?

A. a+b

B. b+a

C. at

D. w

E. x+
View Answers
Question 64
View Answers
Question 65
In standard SQL-92, which of these situations do not require or cannot be handled

through the use of an aggregate SQL function? (Choose 2)

A. Calculating the sum of all the values in a column.

B. Determining the minimum value in a result set.

C. Grouping the results of a query by one or more fields.

D. Calculating the sum of all values in a column and retrieving all the values of

another column that is not part of an aggregate function or GROUP BY clause.

E. Determining the mean average of a column in a group of rows.
View Answers
Question 66
Multidimensional arrays can be sorted using the ______ function.
View Answers
Question 67
When using the default session handler files for using sessions, PHP stores

session information on the harddrive of the webserver.When are those session

files cleaned up?

A. PHP will delete the associated session file when session_destroy() is

called from within a script.

B. When the function session_cleanup() is called, PHP will iterate over all

session files, and delete them if they exceeded the session timeout limit.

C. When the function session_start() is called, PHP will iterate over all

session files, and delete them if they exceeded the session timeout limit.

D. When the function session_start() is called, PHP will sometimes iterate

over all session files, and delete them if they exceeded the session timeout


E. Session files are never removed from the filesystem, you need to use an automated

script (such as a cronjob) to do this.
View Answers
Question 68
What is the order of parameters in the mail() function?

A. subject, to address, extra headers, body

B. to address, subject, extra headers, body

C. to address, subject, body, extra headers

D. subject, to address, body, extra headers
View Answers
Question 69
View Answers
Question 70
The requirement is to return true for the case in which a string $str contains

another string $substr after the first character of $str? Which of the following

will return true when string $str contains string $substr, but only after the first

character of $str?



function test($str, $substr) {

return strpos(substr($str,1), $substr) >= 0;





function test($str, $substr) {

return strrchr($str, $substr) !== false;





function test($str, $substr) {

return strpos($str, $substr) > 0;



A. I only

B. II only

C. III only

D. I and II

E. I and III

F. II and III
View Answers
Question 71
Which of the features listed below do not exist in PHP4? (Choose 2)

A. Exceptions

B. Preprocessor instructions

C. Control structures

D. Classes and objects

E. Constants
View Answers
Question 72
View Answers
Question 73
The following PHP script is designed to subtract two indexed arrays of numbers.

Which statement is correct?


$a = array(5, 2, 2, 3);

$b = array(5, 8, 1, 5);

var_dump(subArrays($a, $b));





$c = count($arr1);


($c != count($arr2))



for($i = 0;

$i < $c;



$arr1[$i] - $arr2[$i];

return $res;



A. The script is valid.

B. Assignments must be made on a single line.

C. It has too many linefeed characters between statements.

D. No, the script is missing curly braces.

E. Yes it is valid, but the script will not work as expected.
View Answers
Question 74
What is the purpose of the escapeshellarg() function?

A. Removing malicious characters.

B. Escaping malicious characters.

C. Creating an array of arguments for a shell command.

D. Preparing data to be used as a single argument in a shell command.

E. None of the above.
View Answers
Question 75
The _________ function can be used to determine if the contents of a string can

be interpreted as a number.
View Answers
Question 76
View Answers
Question 77
What is the name of the function that you should use to put uploaded files into a

permanent location on your server?
View Answers
Question 78
If you have a file handle for an opened file, use the __________ function to send

all data remaining to be read from that file handle to the output buffer.
View Answers
Question 79
Which of the following sentences are not true? (Choose 2)

A. strpos() allows searching for a substring in another string.

B. strrpos() allows searching for a substring in another string.

C. strpos() and strrchr() return -1 if the second parameter is not a substring

of the first parameter.

D. strpos() and strrpos() can return a value that is different from an integer.

E. The second parameter to substr() is the length of the substring to extract.

F. strstr() returns false if the substring specified by its second parameter is

not found in the first parameter.
View Answers
Question 80
Which of the following sentences are correct? (Choose 2)

A. time() + 60*60*100 returns the current date and time plus one hour.

B. time() + 24*60*60 returns the current date and time plus one day.

C. time() + 24*60*60*100 returns the current date and time plus one day
View Answers


Username :
Password :
We have urgent requirement for fresher and 1 year exp candidate.For apply send your resume at career@pcds.co.in

Give plus 1 if you like

  • Questions for PCDS Candidate
Facebook | Twitter

  • Entertainment for PCDS user
   =>Go for Work From Home