Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
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 happens when you run the following MySQL Query ?


2.When working with unfamiliar code, what is the best way to find out in which file a class is defined ?

  $reflection = new ReflectionClass('ClassName');
  echo $reflection->getFileName();

  $out = array();
  exec("grep -r 'Classname' .", $out);

  $classes = get_declared_classes();

3.What is the output of the code below ?

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

4.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';

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

6.What happens if you execute the code below ?

    class someclass
        public $someprop;
        function __construct()
            $this->someprop = 1;

    function somefunc(&$instance) {

    $instance = new someclass;

7.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);

8.How do you access standard I/O and error streams ?

9.What is the output of the following code block? $a = "The quick brown fox jumped over the lazy dog."; $b = array_map("strtoupper", explode(" ", $a)); foreach ($b as $value) { print "$value "; }

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

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

12.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?

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

14.The following code snippet displays what for the resultant array? $a = array(1 => 0, 3 => 2, 4 => 6); $b = array(3 => 1, 4 => 3, 6 => 4); print_r(array_intersect($a, $b));

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

16.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);

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

18.Consider the following table data and PHP code. What is the outcome? Table data (table name "users" with primary key "id"): id name email ------- ----------- ------------------- 1 anna [email protected] 2 betty [email protected] 3 clara [email protected] 5 sue [email protected] PHP code (assume the PDO connection is correctly established): $dsn = 'mysql:host=localhost;dbname=exam'; $user = 'username'; $pass = '********'; $pdo = new PDO($dsn, $user, $pass); $cmd = "SELECT * FROM users WHERE id = :id"; $stmt = $pdo->prepare($cmd); $id = 3; $stmt->bindParam('id', $id); $stmt->execute(); $stmt->bindColumn(3, $result); $row = $stmt->fetch(PDO::FETCH_BOUND);

19.Transactions are used to...

20.What would go in place of ?????? below to make this script execute without a fatal error? $a = 1; $b = 0; /* ?????? */ $c = $a / $b;

21.How does one access standard input/output and error streams in PHP 5?

22.When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used?

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

24.To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.

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

26.What is the best measure one can take to prevent a cross-site request forgery?

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

28.Consider the following script: $oranges = 10; $apples = 5; $string = "I have %d apples and %d oranges"; ??????? What could be placed in place of ?????? to output the string: "I have 5 apples and 10 oranges"

29.If you would like to store your session in the database, you would do which of the following?

30.Setting a cookie on the client in PHP 5 can be best accomplished by:

Finish Quiz