PHP 5 Quiz # 11

Instructions
Quiz: PHP 5 Quiz # 11
Total Questions: 25 MCQs
Time: 25 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 # 11
Question 1 of 25
00:00
  • What will be the output of the following PHP 7.1 code?

    declare(ticks=1);

    function t_handler()

    {

    echo "Example function\n";

    }

    register_tick_function( $x = 1;

    if ($x > 0) {

    $x += 2;

    print($x);

    }

    ?>

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

    interface Exp { public function x();}

    class First implements Exp {

    public function x() {}

    }

    class Second {}

    function x(Exp $e){

    echo get_class($e)."\n";

    }

    x(new First);

    x(new Second);

    ?>


  • In PHP 7.1, which of the following is the correct syntax for a function with iterable generator return type?

  • In PHP 7.1, under which of the following types of scenarios, a TypeError may be thrown?

    i) When the argument type, which is being passed to a function, does not match its corresponding declared parameter type.

    ii) When the returned value from a function does not match the declared function return type.

    iii) When an invalid number of arguments are passed to a built-in PHP function.


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

    class Red {

    public static function b_func() {

    static::a_func();

    }

    public static function a_func() {

    echo "Colour is ",__CLASS__."\n";

    }

    }

    class Blue extends Red {

    public static function run() {

    Red::b_func();

    parent ::b_func();

    self::b_func();

    }

    public static function a_func() {

    echo "Colour is ",__CLASS__."\n";

    }

    }

    class Green extends Blue {

    public static function a_func() {

    echo "Colour is ",__CLASS__."\n";

    }

    }

    Green::run();

    ?>


  • Find the output of the following PHP code.

    $string = echo "The output for '$string' is '$string[-1]'.\n"; ?>

  • While creating or modifying an array in PHP 7.1, what will happen if an empty index operator is applied on a string?

  • In PHP 7.1, which of the following is the correct syntax of the is_iterable() function, which is used to verify whether or not the content of a variable is an iterable value?

  • In PHP 7.1, which of the following operators are non-associative?

  • In PHP 7.1, which of the following options can be used to mark the type declarations for parameters and return values as nullable, by prefixing the type name?

  • In relation to PHP array cast, Booleans can be cast to which of the following options?

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

    -

    abstract class A_Class

    {

    abstract protected function name_P($name);

    }

    class Example extends A_Class

    {

    public function Name_P($name, $separator = ".") {

    if ($name == "Mango") {

    $product = "Fruit";

    } elseif ($name == "Carrot") {

    $product = "Vegitable";

    } else {

    $product ="";

    }

    return "{$name}{$separator} {$product}";

    }

    }

    $class = new Example;

    echo $class->Name_P("Mango"), "\n";

    echo $class->Name_P("Carrot"), "\n";

    ?>

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

    var_dump("pqrstu"[-2]);

    var_dump(strpos("ppqqrr","q", -3)); ?>

  • In relation to PHP 7.1 global space, prefixing a name with which of the following options specifies that the name is required from the global space even in the context of the namespace?

  • Carefully analyze the following program.

    1.

    2.class example

    3.{

    4.static function check()

    5.{

    6.echo "Check\n";

    7.}

    8.function test()

    9.{

    10.echo "Test\n";

    11.}

    12.}

    13.$f = new array("example", "check");    исправил:) $f = array( new example, "check");

    14.$f();

    15.$f = array(new example, test);  исправил:)    $f = array(new example, "test");

    16.$f();

    17.$f = "example::check";

    18.$f();

    19.?>

    The given program was supposed to produce the following output on execution.

    Check

    Test

    Check

    However, the program contains errors. Identify the line numbers that contain errors.


  • In relation to PHP 7.1 throwable interface, which of the following options is used for getting a string representation of a thrown object?

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

    function example()

    {

    static $cnt = 0;

    $cnt++;

    echo $cnt;

    if ($cnt < 5) {

    example();

    }

    $cnt--;

    }

    ?>

  • Which of the following is the correct syntax of the PHP 7.1 magic method, __Sleep()?

  • Find the output of the following PHP 7.1 code.

    example.php

    $x =

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

    echo $x = 'D7';

    for ($i=0; $i<5; $i++) {

    echo ++$x . PHP_EOL;

    }

    ?>

    '>

  • Find the output of the following PHP 7.1 code.

    $example = array(

    5 => "e",

    "5" => "f",

    5.5 => "g",

    true => "i",

    );

    var_dump($example);

    ?>


  • In PHP 7.1, which of the following is the correct syntax of the session_gc() function, which is used to perform session data garbage collection?

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

    $x = 2.98765431;

    $y = 2.98765430;

    $epsilon = 0.00001; if(abs($x-$y) < $epsilon) {

    echo "true";

    }

    ?>

  • Which of the following options are used for specifying a string literal in PHP 7.1?

    i) Single quotes

    ii) Double quotes

    iii) heredoc syntax

    iv) now doc syntax


  • On compilation. the following PHP 7.1 code was supposed to produce the output 24.

    the code lines with errors.


    1.

    2.

    3. class example

    4- {

    5. public $foo;

    G.

    7. public function__construct()[

    8. $this->function = foo()[

    9. return 24;

    10. };

    11. }

    12. }

    13. $exp = new example(]:

    14. echo ($cxp->function)(). PHP_EOL;