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?


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


2.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);
  ?>

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

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

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

6.What happens if you execute the code below ?


<?php
    class someclass
    {
        public $someprop;
        
        function __construct()
        {
            $this->someprop = 1;
        }
    }

    function somefunc(&$instance) {
        unset($instance);
    }

    $instance = new someclass;
    somefunc($instance);
    var_dump($instance);


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

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

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

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

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

13.Transactions are used to...

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

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

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

17.What is the output of the following? $a = 20; function myfunction($b) { $a = 30; global $a, $c; return $c = ($b + $a); } print myfunction(40) + $c;

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

19.In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use _______ in the function declaration.

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

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.Which of the following are not valid ways to embed a variable into a string?

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.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 PCRE regular expression will match the string PhP5-rocks

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

29.If you would like to change the session ID generation function, which of the following is the best approach for PHP 5?

30.Which functions would be needed to translate the following string: I love PHP 5 to the following? 5 PHP EVOL I

Finish Quiz