PHP 5 Quiz # 9

Instructions
Quiz: PHP 5 Quiz # 9
Total Questions: 30 MCQs
Time: 30 Minutes

Note

  • Do not refresh the page while taking the test.
  • Results along with correct answers will be shown at the end of the test.
PHP 5 Quiz # 9
Question 1 of 30
00:00
  • Which of the given options is correct about the following PHP 7.1 code?

    class example

    {

    function do_example()

    {

    echo "Testing example code.";

    }

    }

    $b = new example;

    $b->do_example();

    ?>


  • Which of the following options is used for checking the installed version of PHP 7.1 ?

  • Which of the given statements is correct about the following PHP 7.1 code snippet?

    const C = 2;

    class example {

    const D = C * 2;

    const E = C + self::D;

    const F = }

    echo example::D, PHP_EOL;

    echo example::F;

    ?>

  • In relation to PHP 7.1 error handling, error reporting should be set to which of the following options in the development environment?

  • Which of the given options is the correct output of the following code?

    $result = echo "<pre>$result</pre>";

    ?> 

  • What will be the output of the following PHP 7.1 code?

    for ($a = 2, $b = 1; $a <= 6; $b += $a, print $a, $a++);

    ?>


  • Find the output of the following PHP 7.1 code.

    $a = $b = &$a;

    $b = "I met $b";

    echo $b;

    echo $a;

    ?>

  • Find the output of the following PHP 7.1 code snippet.

    namespace A\B\C;

    const E_ERROR = 32;

    function strlen($s)

    {

    return \strlen($s) - 5;

    }

    echo E_ERROR, "\n";

    echo INI_ALL, "\n";

    echo strlen( if (is_array('abc')) {

    echo "is an example.\n";

    } else {

    echo "is a test.\n";

    }

    ?>

  • In PHP 7.1, the string session_create_id ([ string $prefix ]) function is used for creating a new session id. Which of the following characters are allowed by the parameter prefix?

  • In PHP 7.1, what will be the output of the following code?

    $example = array(2, 4, 6, 8, 10);

    foreach ($example as $x => $value){

    unset($example[$x]);

    }

    print_r($example);

    $example[] = 12;

    print_r($example);

    $example = array_values($example);

    $example[] = 14;

    print_r($example);

    ?>


  • Which of the given statements is correct about the following PHP 7.1 code?

    interface ExampleInterface

    {

    }

    class ExampleClass implements Exampleinterface

    {

    }

    $x = new ExampleClass;

    $y = new ExampleClass;

    $z = $p = 'NotExampleClass';

    var_dump($x instanceof $y);

    var_dump($x instanceof $z);

    var_dump($x instanceof $p);

    ?>

  • What will be the output of the following PHP 7.1 code snippet?

    class Bar

    {

    public function checking()

    {

    return function() {

    var_dump($this);

    };

    }

    }

    $object = new Bar;

    $function = $object->checking();

    $function();

    ?>

  • Which of the following is an invalid constant in PHP 7.1?

  • Which of the given statements is correct about the following PHP 7.1 code?

    $example = 25;

    $b = &$example;

    $b = &(12 * 9);

    function t()

    {

    return 15;

    }

    $b = &t();

    ?>


  • Which of the given options is the correct output of the following PHP 7.1 program?

    function swap(&$x, &$y): void

    {

    if ($x === $y) {

    return;

    }

    $exp = $x;

    $x = $y;

    $y = $exp;

    }

    $var1 = 12;

    $var2 = 20;

    var_dump(swap($var1, $var2), $var1, $var2);?>


  • In PHP 7.1, which of the following cast options can be used for explicitly converting a value to integer?

  • What will be the output of the following PHP 7.1 code?

    class First

    {

    private $foo = 2;

    protected $bar = 4;

    protected function A_funct()

    {

    return 5;

    }

    public function B_funct()

    {

    return new class($this->foo) extends First {

    private $test;

    public function _construct($foo)

    {

    $this->test = $foo;

    }

    public function C_funct()

    {

    return $this->bar + $this->test + $this->A_funct();

    }

    };

    }

    }

    echo (new First)->B_funct()->C_funct();?>


  • What will be the output of the following PHP 7.1 code?

    var_dump(0 == "x");

    var_dump("2" == "02");

    var_dump("20" == "2e2");

    var_dump(200 == "2e4");

    switch ("x") {

    case 0:

    echo "0";

    break;

    case "x":

    echo "x";

    break;

    }

    ?>

  • What will be the output of the following PHP 7.1 code?

    for($a=0,$b=20; $a<50; $a++) {

    while($b--) {

    if($b==8) goto end;

    }

    }

    echo "a = $a";

    end:

    echo ?>

  • In PHP 7.1, what will be the output of the following code?

    $E_array = array(

    "test" => "code",

    64 =>46,

    "multi" => array(

    "dimensional" => array(

    "array" => "test"

    )

    )

    );

    var_dump($E_array["test"]);

    var_dump($E_array [64]);

    var_dump($E_array["multi"]["dimensional"]["array"]);

    ?>


  • What will be the output of the following PHP 7.1 code?

    class Example

    {

    public function abcFunction()

    {

    return Closure::fromCallable([$this, }

    private function privateFunction($param)

    {

    var_dump($param);

    }

    }

    $expFunc = (new Example)->abcFunction();

    $expFunc('My New Example');?>

  • In PHP 7.1, which of the following options can be the key of an array?

  • What will be the output of the following PHP 7.1 code snippet?

    var $example = var $array = array('My name is A.', 'My name is B.', 'My name is C.');

    var $r = 'My name is r.';

    }

    $f = new f();

    $example = 'example';

    $b = array('f', 'example', 'b', 'c');

    echo $f->$example. "\n";

    echo $f->{$b[1]} . "\n";

    $start = 'exa';

    $end = 'mple';

    echo $f->{$start. $end}. "\n";

    $array = 'array';

    echo $f->{$array[1]}. "\n";

    ?>

  • In the following PHP 7.1 program, which of the given code statements should replace ??? to obtain 12345 as output?

    function recursive($var){

    echo $var;

    if($var < 5){

    ???

    }

    }

    $a = 1;

    recursive($a);

    ?>

  • Find the output of the following code snippet.

    $bar = <<< 1;Anna;eats mangoes

    2;Mark;eats apples

    EOF;

    function bar_parser($bar) {

    foreach (explode("\n", $bar) as $I) {

    $foo = explode(';', $I);

    $id = array_shift($foo);

    yield $id => $foo;

    }

    }

    foreach (bar_parser($bar) as $id => $foo) {

    echo "$id:\n";

    echo" $foo[0]\n";

    echo" $foo[1]\n";

    }

    ?>

  • What will be the output of the following PHP 7.1 code?

    $st = echo "At index -4, the character is $st[-4].", PHP_EOL;

    $st[-3] = 'o';

    echo "Replacement at index -3 to o gives $st.", PHP_EOL;

    ?>

  • What will be the output of the following PHP 7.1 code snippet?

    <?php

    function xrange($first, $last, $forward = 1)

    { if ($first < $last) {

    if ($forward <= 0) {

    throw new LogicException('The value of forward should be positive');

    }

    for ($i = $first; $i <= $last; $i += $forward){

    yield $i;

    }

    } else {

    if ($forward >= 0) {

    throw new LogicException('The value of forward should be negative');

    }

    for ($i = $first; $i >= $last; $i += $forward){

    yield $i;

    }

    }

    }

    echo "\n";

    echo 'Output is: ';

    foreach (xrange(1, 7, 2) as $num) {

    echo "$num";

    }

    ?>


  • In PHP 7.1, which of the following is the correct syntax of the function, Closure::from Callable, which is used to convert a callable into a closure?

  • What will be the output of the following PHP 7.1 code?

    var_dump((bool) -1);

    var_dump((bool) 1.5e5);

    var_dump((bool) "false");

    ?>


  • What will be the output of the following PHP code.

    $x = array("x" => "Adam", "y" => "Binca");

    $y = array("x" => "Avin", "y" => "Beth", "z" => "Chris");

    $z = $y + $x;

    $x += $y;

    var_dump($x);

    ?>