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 is the default value for the "max_execution_time" setting when running PHP as a CLI SAPI ?

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

4.What is the output of the code below ?


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

5.What is the output of the code below ?

  
    <?php
    namespace animals;

    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'on');

    class Cat
    {
      static function Definition()
      {
        return 'Cats are ' . __NAMESPACE__;
      }
    }

    namespace animals\pets;

    class Cat
    {
      static function Definition()
      {
        return 'Cats are ' . __NAMESPACE__;
      }
    }

    echo Cat::Definition();    
  

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

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

8.When running PHP's built in FastCGI Process Manager (FPM) which of the following statements are true ?

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

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

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

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

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

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.Which of the following tags are an acceptable way to begin a PHP Code block?

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

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

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

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

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

21.What is wrong with the following code? function duplicate($obj) { $newObj = $obj; return $newObj; } $a = new MyClass(); $a_copy = duplicate($a); $a->setValue(10); $a_copy->setValue(20);

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

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

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

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

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

27.To destroy one variable within a PHP session you should use which method in PHP 5?

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

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

30.Consider the following function: function redirect($url) { // Check to make sure we haven't already sent // the header: if(/*???????*/) { header("Location: $url"); } } What conditional should replace the ????? above?

Finish Quiz