PHP

PHP

Functions has 9 Questions
Which one of the following is the right way of defining a function in PHP?

function { function body }
data type functionName(parameters) { function body }
functionName(parameters) { function body }
function fumctionName(parameters) { function body }
Type Hinting was introduced in which version of PHP?

PHP 4
PHP 5
PHP 5.3
PHP 6
What will happen in this function call?
  1.     <?php
  2.     function calc($price, $tax)	
  3.     {
  4.         $total = $price + $tax;
  5.     }
  6.     $pricetag = 15;
  7.     $taxtag = 3;
  8.     calc($pricetag, $taxtag);	
  9.     ?>

Call By Value
Call By Reference
Default Argument Value
Type Hinting
What will be the output of the following PHP code?
  1.     <?php
  2.     function calc($price, $tax="")
  3.     {
  4.         $total = $price + ($price * $tax);
  5.         echo "$total"; 
  6.     }
  7.     calc(42);	
  8.     ?>

Error
0
42
84
Which of the following are valid function names? i) function() ii) €() iii) .function() iv) $function()

Only ii)
None of the mentioned.
All of the mentioned.
iii) and iv)
What will be the output of the following PHP code?
  1.     <?php
  2.     function a()
  3.     {
  4.         function b()
  5.         {
  6.             echo 'I am b';
  7.  	}
  8.         echo 'I am a';
  9.     }
  10.     a();
  11.     a();
  12.     ?>

I am b
I am bI am a
Error
I am a Error
What will be the output of the following PHP code?
  1.     <?php
  2.     function a()  
  3.     {
  4.         function b()
  5.         {
  6.             echo 'I am b';
  7.  	}
  8.         echo 'I am a';
  9.     }
  10.     b();
  11.     a();
  12.     ?>

I am b
I am bI am a
Error.
I am a Error
A function in PHP which starts with __ (double underscore) is know as..

Magic Function
Inbuilt Function
Default Function
User Defined Function
What will be the output of the following PHP code?
  1.     <?php
  2.     function foo($msg)
  3.     {
  4.         echo "$msg";
  5.     }
  6.     $var1 = "foo";
  7.     $var1("will this work");
  8.     ?>

Error.
$msg
0
will this work