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.Considering the code below, which of these statements are true?

    ini_set("allow_url_fopen", "1");
    $page = file_get_contents("http://www.codepunker.com");
    echo "Successfully fetched website contents";
    echo "An error has occurred";

2.Assuming that the code below is in a file named "test.php" and that PHP has full rights over the file, what happens if the file is executed from the command line without any arguments ?

  exec("rm -f " . dirname(__FILE__) . "/" .  $argv[0]);

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

4.Considering the following code which of the statements below is true ?

    class entity {
        public $name;
    $human = new entity();
    $dog = new entity();
    $human->name = 0;
    $dog->name = "";

5.When dealing with cloned objects in PHP, which of the following statements are true ?

6.Which of th following statements about object serialization are true ?

7.What happens if you execute the code below ?

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

    function somefunc(&$instance) {

    $instance = new someclass;

8.Which of the following functions will sort an array in ascending order by value, while preserving key associations?

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.What is the output of the following code block? $array = array(1 => 0, 2, 3, 4); array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3))); var_dump($array);

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

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.What is the best way to iterate and modify every element of an array using PHP 5?

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

16.What is the output of the following? $a = 010; $b = 0xA; $c = 2; print $a + $b + $c;

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

18.What is the difference between the ``include`` and ``require`` language constructs?

19.How to access standard error stream in PHP ?

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.Which of the following php.ini directives should be disabled to improve the outward security of your application?

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

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.When comparing two strings, which of the following is acceptable?

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

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

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

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

29.How does one create a cookie which will exist only until the browser session is terminated?

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

Finish Quiz