Test HTTP Requests Tools Blog Learn Quizzes Smile API Log In / Sign Up
Test HTTP Requests Tools Blog Learn Quizzes Smile API Log In / Sign Up
« Return to the quizzes list
We have updated the website and our policies to make sure your privacy rights and security are respected.
Click here to learn more about the way our website handles your data.

Remove this message.

Advanced PHP Quiz

Topic: PHP/MySQL Last updated on: 01-22-2018

This is an advanced PHP Quiz. It contains questions for seasoned developers about namespaces, traits, handlers and settings, command line execution, exception handling, OOP and other modern PHP features and functions.

1.What is the output of the code below ?

  $a = array();
  $a[0] = 1;
  echo ($a != null) ? 'True' : 'False';

2.What is the output of the code below ?

    namespace animals;

    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'on');

    class Cat
      static function Definition()
        return 'Cats are ' . __NAMESPACE__;

    namespace animals\pets;

    class Cat
      static function Definition()
        return 'Cats are ' . __NAMESPACE__;

    echo Cat::Definition();    

3.What is the output of the code below ?

    $a = array('one'=>'php', 'two'=>'javascript', 'three'=>'python');
    $b = array('python', 'javascript', 'php');

    if(array_values(array_reverse($a)) === $b)
      echo 'true';
      echo 'false';

4.Which of the statements about traits below are true ?

5.Which of the following is not valid syntax for creating a new array key?

6.What is the output of this code snippet? $a = array(0.001 => 'b', .1 => 'c'); var_dump($a);

7.Which of the following functions could be used to break a string into an array?

8.What should go in the missing line ????? below to produce the output shown? $array_one = array(1,2,3,4,5); $array_two = array('A', 'B', 'C', 'D', 'E'); ??????? print_r($array_three); Result: Array ( [5] => A [4] => B [3] => C [2] => D [1] => E )

9.Which of the following functions are used with the internal array pointer to accomplish an action?

10.Given the following array: $array = array(1,1,2,3,4,4,5,6,6,6,6,3,2,2,2); The fastest way to determine the total number a particular value appears in the array is to use which function?

11.The ____ construct is particularly useful to assign your own variable names to values within an array.

12.What is the output of the following PHP code? define("FOO", 10); $array = [10 => FOO,"FOO" => 20]; print $array[$array[FOO]] * $array["FOO"];

13.What is the output of the following PHP script? $a = 1; $b = 2.5; $c = 0xFF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print ($f + $e);

14.What SimpleXML function is used to parse a file?

15.What is the output of the following? $a = 20; function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;

16.In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.

17.What is wrong with the following code? function duplicate($obj) { $newObj = $obj; return $newObj; } $a = new MyClass(); $a_copy = duplicate($a); $a->setValue(10); $a_copy->setValue(20);

18.How can you modify the copy of an object during a clone operation?

19.What is the primary difference between a method declared as static and a normal method?

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

21.For an arbitrary string $mystring, which of the following checks will correctly determine if the string PHP exists within it?

22.Which of the following are not valid ways to embed a variable into a string?

23.What variable reference would go in the spots indicated by ????? in the code segment below? $msg = "The Quick Brown Foxed Jumped Over the Lazy Dog"; $state = true; $retval = ""; for ($i = 0; (isset(??????)); $i++) { if($state) { $retval .= strtolower(?????); } else { $retval .= strtoupper(?????); } $state = !$state; } print $retval;

24.A fingerprint of a string can be determined using which of the following?

25.Which function is best suited for removing markup tags from a string?

26.Identify the best approach to compare two variables in a binary-safe fashion

27.Which string does the following PCRE regular expression match? $regex = "/^([a-z]{5})[1-5]+([a-z]+)/";

28.Which PCRE regular expression will match the string PhP5-rocks

29.To destroy one variable within a PHP session you should use which method in PHP 5?

30.Which of the following is not a valid fopen() access mode:

Finish Quiz