Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
Test HTTP Requests Tools Blog PHP Quiz API Log In With Github
You are seeing the archive version of the website.
Click here to go to the live website

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 the script below is executed ?


  <?php
    namespace CustomArea;
    error_reporting(E_ALL);
    ini_set("display_errors", "on");
    function var_dump($a)
    {
      return str_replace("Weird", $a, "Weird stuff can happen");
    }
    $a = "In programming";
    echo var_dump($a);
  ?>

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


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


  <?php
  $out = array();
  exec("grep -r 'Classname' .", $out);
  var_dump($out);
  ?>


  $classes = get_declared_classes();
  var_dump($classes);

3.What is the output of the code below ?

    
    $now  = new DateTime();
    $now2 = new DateTime();

    $ago  = new DateInterval('P4Y10M3W');
    $ago2 = new DateInterval('P4Y10M2W7D');

    $then  = $now->sub($ago);
    $date1 = $then->format('Y-m-d');

    $then2 = $now2->sub($ago2);
    $date2 = $then2->format('Y-m-d');

    var_dump ($date1 === $date2);
    

4.What is the output of the code below ?


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

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

6.How does Opcode Cache improve performance in PHP 5.5+ ?

7.What is the output of the following PHP script?

                    <?php 
                        $a = 1;
                        $b = 2.5;
                        $c = 0xFF;
                        $d = $b + $c;
                        $e = $d * $b;
                        $f = ($d + $e) % $a;
                        print ($f + $e);
                  

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

9.Which function would you use to add an element to the beginning of an array?

10.What is the result of the following code snippet? $array = array('a' => 'John', 'b' => 'Coggeshall', 'c' => array('d' => 'John', 'e' => 'Smith')); function something($array) { extract($array); return $c['e']; } print something($array);

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

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

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

14.Which of the following tags are an acceptable way to begin a PHP Code block?

15.Which of the following are valid PHP variables?

16.Which one of the following XML declarations is NOT valid?

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

18.What does the following function do, when passed two integer values for $p and $q? function magic($p, $q) { return ($q == 0) ? $p: magic($q, $p % $q); }

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

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

21.What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?

22. Which of the following list of potential data sources should be considered trusted?

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

24.When implementing a permissions system for your Web site, what should always be done with regards to the session?

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

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

27.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"

28.To force a user to redirect to a new URL from within a PHP 5 script, which of the following should be used?

29.Setting a HTTP cookie on the client which is not URL-encoded is done how in PHP 5?

30.During an HTTP authentication, how does one determine the username and password provided by the browser?

Finish Quiz