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.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.What output will this code produce ?

    class Disney
        public $cartoon;

        function __construct($cartoon)
            $this->cartoon = $cartoon;

    $disney = new Disney("The Beauty and The Beast");
    $waltDisney = $disney;
    $waltDisney->cartoon = "Pinocchio";
    echo $disney->cartoon;

3.What happens when the code below is executed ?

    class foo
      private $variable;

      function __construct()
        $this->variable = 1;

      function __get($name)
        return $this->$name;
    $a = new foo;
    echo $a->variable;

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.When dealing with cloned objects in PHP, which of the following statements are true ?

6.What is the best way to store and verify passwords in PHP ?

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.Which of the following is not valid syntax for creating a new array key?

9.Which from the following list is not an appropriate use of an array?

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

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

12.What is the best way to iterate and modify every element of an array using PHP 5?

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

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

15.Which of the following will NOT instantiate a DateTime object with the current timestamp?

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

17.Which technique should be used to speed up joins without changing their results?

18.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.

19.Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?

20.Consider the following code: session_start(); if(!empty($_REQUEST['id']) && !empty($_REQUEST['quantity'])) { $id = scrub_id($_REQUEST['id']); $quantity = scrub_quantity($_REQUEST['quantity']) $_SESSION['cart'][] = array('id' => $id, 'quantity' => $quantity) } /* .... */ What potential security hole would this code snippet produce?

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

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

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.What is the output of the following code? $string = "14302"; $string[$string[2]] = "4"; print $string;

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

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

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

28.To destroy a PHP session completely, one must which of the following?

29.When uploading a file using HTTP, which variable can be used to locate the file on PHP's local filesystem?

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

Finish Quiz