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?


<?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.When running PHP's built in FastCGI Process Manager (FPM) which of the following statements are true ?

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


5.Which of the following is not valid syntax for creating a new array key?

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

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

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

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

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

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

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

13.Which one of the following XML declarations is NOT valid?

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

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

16.What is the output of the following function? function &find_variable(&$one, &$two, &$three) { if($one > 10 && $one < 20) return $one; if($two > 10 && $two < 20) return $two; if($three > 10 && $three < 20) return $three; } $one = 2; $two = 20; $three = 15; $var = &find_variable($one, $two, $three); $var++; print "1: $one, 2: $two, 3: $three";

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

18.The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.

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

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

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

22. Which of the following list of potential data sources should be considered trusted?

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

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

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

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

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

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

29.Which of the following is not a valid fopen() access mode:

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

Finish Quiz