Try to answer these 300+ PHP 5 MCQs and check your understanding of the PHP 5 subject.
Scroll down and let's begin!

1: Which function will list files and directories inside the specified path?

A.   fopen()

B.   fscan()

C.   scandir()

D.   opendir()

E.   readdir()

2: PDO::beginTransaction() turns off autocommit mode.

A.   True

B.   False

3: Which of the following function is used to display the properties of variable?

A.   explain

B.   define

C.   none of the above

D.   var_dump

4: Which function can be used to rename files?

A.   fputs()

B.   rename()

C.   fwrite()

D.   copy()

E.   die()

5: What is PEAR in PHP?

A.   PHP Extension and Application Repository

B.   There is no PEAR in PHP.

C.   PHP Extended Applications aRchive

6: What is the default timezone in pHP5

A.   Gambier/Islands

B.   French/Polynesia

C.   Europe/Zurich

7: What is the correct way to open the file "time.txt" as readable?

A.   fopen("time.txt","r");

B.   open("time.txt");

C.   open("time.txt","read");

D.   fopen("time.txt","w+");

8: The function used to iterate over array and object.

A.   while

B.   dowhile

C.   foreach

D.   for

9: How can I identify the server IP address in PHP?

A.   $_ADDRESS['server_ip'];


C.   server_id();

D.   server_addr();

10: Can I Use Proxy In Php Curl



11: What Does OOM mean?

A.   Object Original Miscleneaous

B.   Object Orientaton Mechnism

C.   Object Over Masterclass

D.   Object Oriented Model

E.   Original Overlap Model

12: What is the correct way to include the file "" ?





13: How do you write "Hello World"?

A.   echo 'Hello World!"

B.   "Hello World!"

14: Which of the following function is used to check type of array

A.   isArray

B.   is_array

C.   array_valid

D.   valid_array

15: How do you kill or destroy a session?

A.   kill_session()

B.   session_destroy();

C.   destroy_session()

D.   reset_session()

E.   session_kill()

16: Include files must have the file extension ".inc"

A.   Yes

B.   No

17: How to open file in read/write mode?

A.   $handle = fcopen("", "r");

B.   $handle = fileopen("", "r+");

C.   $handle = fopen("", "r");

D.   $handle = fopen("", "r+");

E.   $handle = fcopen("", "r+");

18: $x = 10.88; echo (int) $x;

A.   1

B.   0

C.   11

D.   10

19: What operator is used to test if two values are identical in every way

A.   ===

B.   !==

C.   instanceof

D.   ==

E.   =

20: If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?

A.   preg_* regular expression functions

B.   ereg* regular expression functions

C.   strtok() using regular expressions

D.   strregex* regular expression functions

21: True or false? One can include (”abc.PHP”) two times in a PHP page “makeit.PHP”.

A.   False

B.   True

22: Which function would you use to append one or more elements to the end of the array?

A.   array_push()

B.   array_unshift()

C.   array_shift()

D.   array_pop()

23: A fatal error would be caught by






24: (8 < 1 || 4 >= 4 ) will return

A.   True

B.   False

25: Which of the following responsible for change the current directory?

A.   chdir()

B.   closedir()

C.   opendir()

D.   dir()

E.   rewinddir()

26: How can you delete a file using a php function?

A.   drop

B.   delete

C.   deletefile

D.   remove

E.   unlink

27: What function in PHP allows you to find the position of the first occurrence of a substring?

A.   strtok()

B.   strripos()

C.   str_repeat()

D.   strpos()

E.   substr()

28: Which array function checks if the specified key exists in the array?

A.   array_key_exists()

B.   is_array()

C.   array_search()

D.   isset()

A.   fgets

B.   fopen

C.   fappend

D.   fclose

E.   fwrite

30: What is the name of the function to check that the variable type is an object?

A.   (none of these)

B.   is_object

C.   TypeOject

D.   isObject

31: The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.

A.   abstract

B.   incomplete

C.   implements

D.   protected

32: Which of the following responsible for generates the backtrace

A.   debug_backtrace()

B.   trigger_error()

C.   debug_print_backtrace()

D.   user_error()

E.   error_get_last()

33: Which of the following is not a boolean false

A.   False

B.   1

C.   (none of these)

D.   false

34: $a = &$b; $b = 'Mary?' print $a;

A.   Fatal error

B.   Mary?

C.   Empty output

D.   Notice

E.   Warning

35: In mail($param1, $param2, $param3, $param4), the $param2 contains:

A.   The subject

B.   The recipient

C.   The header

D.   The message

36: What is the best way to URL encode a string?

A.   urldecode( $str )

B.   urlencode( $str )

C.   urlcode( $str )

D.   encode_url( $str )

E.   encodeurl( $str )

37: You start a transaction with PDO::beginTransaction(). How do you roll back a transaction?

A.   PDO::stopTransaction()

B.   PDO::rollbackTransaction()

C.   PDO::rollBack()

D.   PDO::abortTransaction()

38: Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the Mountain Standard Time (MST) Time Zone, which of the follow outputs: March 10, 2001, 5:16 pm

A.   date("F j, Y, g:i a");

B.   date("j, n, Y");

C.   date("m.d.y");

D.   date('h-i-s, j-m-y, it is w Day');

E.   date("D M j G:i:s T Y");

39: You start a transaction with PDO::beginTransaction(). How do you commit a transaction?

A.   PDO::endTransaction()

B.   PDO::commitTransaction()

C.   PDO::stopTransaction()

D.   PDO::closeTransaction()

E.   PDO::commit()

40: function foobar( ) { $a = func_get_args( ); return $a[2]; } print foobar('a',1,'b',2); What would the output be?

A.   b

B.   2

C.   1

D.   a

E.   a2

41: ( (4 >= 4 && 8 < 1) || (44 == 33 || 5 > 3) ) will return



42: Which of the following functions split the string and return the array?

A.   strsplit()

B.   splitstr()

C.   stringsplit()

D.   str_split()

E.   split_str()

43: True or false? PHP provides the goto in the latest version.

A.   True

B.   False

44: Which of these functions will not result in a runtime error if the file requested does not exist or can't be opened?

A.   require()

B.   include()

C.   nowarn()

D.   getFile()

45: How do you make PHP use a class file without having to require or include it manually?

A.   Define $_MAP superglobal

B.   Set default_lib_path variable in php.ini

C.   Use set_class_handler($class_handler) function

D.   Define __autoload($class) magic function

E.   There's no way to do it

46: What visibility level will this class property get in PHP5? var $cool = true;

A.   protected

B.   private

C.   public

D.   var keyword is no longer valid in PHP5

47: What will the following code output: "lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); ksort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val\n"; } ?>

A.   a = apple b = banana c = lemon d = orange

B.   d = apple a = banana b = lemon c = orange

C.   a = orange b = banana c = apple d = lemon

D.   d = lemon a = orange b = banana c = apple

E.   a = lemon b = orange c = banana d = apple

48: How do you connect mysql with the use of PHP5 new functions?

A.   (both answers are correct)

B.   $connection = new mysqli('localhost', 'user', 'pass', 'test');

C.   $user = 'user'; $pass = 'pass'; $connection = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

49: What is the difference between $message and $$message?

A.   Memory pointer

B.   Classic example of PHP’s variable variables

C.   Error

50: The _______ method will be called automatically when an object is represented as a string.

A.   __toString()

B.   __getString()

C.   getString()

D.   __get()