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


<?php 
    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;

2.What happens when the code below is executed ?


  <?php
    class foo
    {
      private $variable;

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

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

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

4.What is the output of the code below ?

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

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

5.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 "; }

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

7.If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use?

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

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

10.Which of the following are valid PHP variables?

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

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? $a = 010; $b = 0xA; $c = 2; print $a + $b + $c;

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

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

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

17.What would you replace ??????? with, below, to make the string Hello, World! be displayed? function myfunction() { /* ??????? */ print $string; } myfunction("Hello, World!");

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

19.When an object is serialized, which method will be called, automatically, providing your object with an opportunity to close any resources or otherwise prepare to be serialized?

20.Which of the following php.ini directives should be disabled to improve the outward security of your application?

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

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

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

24.Which of the following is the best way to split a string on the "-=-" pattern?

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

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.Which string does the following PCRE regular expression match? $regex = "/^([a-z]{5})[1-5]+([a-z]+)/";

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

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

30.Consider the following HTML fragment: <select name="???????" multiple> <option value="1">Item #1</option> <!-- ... more options ... --> </select> Which of the following name attributes should be used to capture all of the data from the user in PHP?

Finish Quiz