Home / CSE / PHP - CS :: Functions in PHP

CSE :: PHP - CS

  1. Which one of the following is the right way of defining a function in PHP?

  2. A.

     function { function body }

    B.

     data type functionName(parameters) { function body }

    C.

     functionName(parameters) { function body }

    D.

     function fumctionName(parameters) { function body }


  3. Type Hinting was introduced in which version of PHP?

  4. A.

     PHP 4

    B.

     PHP 5

    C.

     PHP 5.3

    D.

     PHP 6


  5. What will happen in this function call?

    <?php

    function calc($price, $tax)

    {

    $total = $price + $tax;

    }

    $pricetag = 15;

    $taxtag = 3;

    calc($pricetag, $taxtag);

    ?>

  6. A.

     Call By Value

    B.

     Call By Reference

    C.

     Default Argument Value

    D.

     Type Hinting


  7. What will be the output of the following PHP code?

    <?php

    function calc($price, $tax="")

    {

    $total = $price + ($price * $tax);

    echo "$total";

    }

    calc(42);

    ?>

  8. A.

     Error

    B.

     0

    C.

     42

    D.

     84


  9. Which of the following are valid function names? 1. function() 2. €() 3. .function() 4. $function()

  10. A.

     Only 2

    B.

     None of the mentioned

    C.

     All of the mentioned

    D.

     3 and 4


  11. What will be the output of the following PHP code?

    <?php

    function a()

    {

    function b()

    {

    echo 'I am b';

    }

    echo 'I am a';

    }

    a();

    a();

    ?>

  12. A.

     I am b

    B.

     I am bI am a

    C.

     Error

    D.

     I am a Error


  13. What will be the output of the following PHP code?

    <?php

    function a()

    {

    function b()

    {

    echo 'I am b';

    }

    echo 'I am a';

    }

    b();

    a();

    ?>

  14. A.

     I am b

    B.

     I am bI am a

    C.

     Error

    D.

     I am a Error


  15. What will be the output of the following PHP code?

    <?php

    $op2 = "blabla";

    function foo($op1)

    {

    echo $op1;

    echo $op2;

    }

    foo("hello");

    ?>

  16. A.

     helloblabla

    B.

     Error

    C.

     hello

    D.

     helloblablablabla


  17. A function in PHP which starts with ______ (double underscore) is know as.

  18. A.

     Magic Function

    B.

     Inbuilt Function

    C.

     Default Function

    D.

     User Defined Function


  19. What will be the output of the following PHP code?

    <?php

    function foo($msg)

    {

    echo "$msg";

    }

    $var1 = "foo";

    $var1("will this work");

    ?>

  20. A.

     Error

    B.

     $msg

    C.

     0

    D.

     Will this work