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 you run the following MySQL Query ?

  
  CREATE TABLE PRIMARY (ID int);
  

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

4.Considering the following code which of the statements below is true ?


    class entity {
        public $name;
    }
    $human = new entity();
    $dog = new entity();
    $human->name = 0;
    $dog->name = "";

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

6.Which of the following functions will sort an array in ascending order by value, while preserving key associations?

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

8.Which of the following functions could be used to break a string into an array?

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

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

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 script? $a = 1; $b = 2.5; $c = 0xFF; $d = $b + $c; $e = $d * $b; $f = ($d + $e) % $a; print ($f + $e);

13.What would go in place of ?????? below to make this script execute without a fatal error? $a = 1; $b = 0; /* ?????? */ $c = $a / $b;

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

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

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

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

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

19.For an arbitrary string $mystring, which of the following checks will correctly determine if the string PHP exists within it?

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

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

22.Given the two values below, which of the following possibilities will print 10 foos20 bars? $var1 = "10 foos"; $var2 = "20 bars"; print ???????;

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.If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?

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

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

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

29.How does one create a cookie which will exist only until the browser session is terminated?

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

Finish Quiz