Test Answers For PHP Exam

Ques: The setrawcookie() method of setting cookies is different from PHP standard method of cookie setting as:
a. It does not allow expiry time to be set
b. It can be used only once
c. It does not URL-ENCODE the value on its own
d.It does not allow domain setting
Ans: C
Ques: You need to keep an eye on the existing number of objects of a given class without introducing a non-class varibale. which of the following makes this happen?
a. Add a member varibale that gets incremented in the default constructer and decremented the destructer.
b. Add a local variable that gets incremented in each constructer and decremented in the desructer
c. Add a static member variable that gets incremented in each constructer and decreented in the destructor
d. This cannot be accomplished since the creation of objects is being done dynamically via “new”
Ans: c
Ques: which of the following variable declaration within a class is invalid in PHP5?
a. private $type = “moderate”;
b. var $term = 3;
c. public $amn = “500″;
d. protected $name = ‘Quantes Private Limited’;
Ans: d
Ques: which of the following is not valid PHP parser tag?
a. script
b. ?p
c. %
d. ?php;
Ans: c
Ques: How can you hide the fact that web pages are written in PHP?
a. By using AddType application/X-httpd-php asp
b. Specify all file names without any dot and extension
c. By using .htaccess diretive in Apeche
d. All of the above
Ans: C
Ques: What is the output of the following code?
$a = 3;
$b = 2;
echo (int)$a/(int)$b
?>
a. 1
b. 1.5
c. 2
d. 3
e. Eroor
Ans: b

Ques: Which one is correct?
a. $s = fwrite (“a string here”);
b. $s = fwrite ($fp,”a string here”);
c. $s = fwrite (“a string here”,$fp);
d. non of the above
Ans: b
Ques: Which of the following set of operations is not valid in PHP 5?
a. >, >=
b. =,==
c. !==,!==
d. +=, *=
Ans: C
Ques: Late PHP version support remote file accessing for the functions:
a. include()
b. include_once()
c. require_once()
d. All of the above
Ans: D

Ques: What will be the output of the following script?
$count=50;
function Argument()
{
$count++;
echo $count;
}
Argument()
?>
a. It will print 50
b. It will print 51
c. It will print 52
d. It will print 1
Ans: D
Ques: which of the following are used for code reuse?
a. Loops
b. functions
c. Database
d. include files
Ans: B,D
Ques: which of the following is the corect way of specifying default value?
a. Function GetDiscount($Type = “Special”) {………}
b. Function GetDiscount(Type := “Special”) {………}
c. Function GetDiscount($Type: = “Special”) {………}
d. Function GetDiscount($Type : “Special”) {………}
Ans: b
Ques: Which of the following are “magic constant”?
a. __LINE__
b. __FILE__
c __PRETTY_FUNCTION__
d __CLASS__
e. __METHOD__
Ans: c
Ques: you have defined three variables $to, $subject, and $body to send an email. Which of the following methods would you use for sending an email?
a. mail($to, $subject,$body)
b. sendmail($to, $subject,$body)
c. mail(to, subject,body)
d. sendmail(to, subject,body)
Ans: a
Ques: Which one of the following is turnary operator?
a. &
b. =
c. :?
d. ?:
e. +=
f. &&
Ans: D
Ques: What is the result of the following Exprssion?
5+2*4+6
a. 70
b. 19
c. 34
d. 21
Ans: B
Ques: The default value of register global in PHP is:
a. Off
b. On
Ans: A
Ques: What would b the outpur of the following code?
$string = ‘good day’;
$string = ucword($string);
echo $string;
?>
a. good day
b. GOOD DAY
c. Good Day
d. non of the above
Ans: C
Ques: If you want to pass a value to a function by reference, the correct way is:
a. function ModifyReport(&$Rptfile){}
b. function ModifyReport($Rptfile){}
c. function ModifyReport(ByRef $Rptfile){}
d. function ModifyReport(&Rptfile){}
Ans: 
 
Ques 1 : Which function can be used to delete a file?
       Ans: delete()


Ques 2  : What is the string concatenation operator in PHP?
Ans. Dot .

Ques 3   :What is the correct PHP command to use to catch any error messages within the code?
Ans:  set_error_handler(“handleError”)

Que 4: Which of the following is not a PHP magic constant?
Ans: _TIME_

Ques 5 : Which of the following will start a session?
Ans: session_start();
Ques 6 : What will be the output of the following code?
<?php var_dump (3*4); ?>
Ans: int(12)

Ques 7 : Which of the following is useful for method overloading?
Ans: _call,_get,_set

Ques 8 : What enctype is required for file uploads to work?
Ans: “multipart/form-data”
What is the string concatenation operator in PHP?

Ques 9  : What is the correct way to send a SMTP (Simple Mail Transfer Protocol) email using PHP?
Ans: mail($EmailAddress, “Subject”, $MessageBody);


Ques 10: Which of the following characters are taken care of by htmlspecialchars?
Ans: All of these

Ques 11 : which function is used to delete a file
Ans: (A)

Ques 12: What is the output of the following code?
<?php echo 0×500; ?>
Ans: 1280

Ques 13: Which of the following is the correct way to check if a session has already been started?
Ans: if (session_id()) echo ‘session started’;

Ques 14: Which of the following is not a file-related function in PHP?
Ans: fappend

Ques 15: What is the correct syntax of mail() function in PHP?
Ans: mail ($to, $subject, $message,$headers)

Ques 16: Consider the following class:  1  class Insurance 2  { 3      function clsName() 4      { 5          echo        get_class($this); 6      } 7  } 8  $cl = new Insurance(); 9  $cl->clsName(); 10 Insurance::clsName();  Which   of the following lines should be commented to print the class name without errors?
Ans: Line 10

Ques 17: What function should you use to join array elements with a glue string?
Ans: implode

Ques 18: Which of the following is not a predefined constant?
Ans: __FILE__

Ques 19. What would occur if a fatal error was thrown in your PHP program?
Ans: A , stop execution at the point where the error occurred

Ques 20:  Which of the following will read an object into an array variable?
Ans: A

Ques 21.: Which function will suitably replace ‘X’ if the size of a file needs to be checked?  $size=X(filename);
Ans: filesize

Ques 22: Which of the following is true about the singleton design pattern?
Ans: B (A singleton means that a class can have only one instance)
Ques 23. Which of the following attributes is needed for file upload via a form?
Ans: enctype=”multipart/form-data”>
Ques 24: Which of the following is used to maintain the value of a variable over different pages?
Ans: Session_register()
Ques 25: Which of the following is correct about Mysqli and PDO?
Ans: (A)
Ques 26:  Which of the following is incorrect with respect to separating PHP code and HTML?
Ans:  (B)
Ques 27: Which of the following statements is incorrect?
Ans: (C)
Ques 28: Which of the following is not a valid DOM method in PHP?
Ans: (A)
Ques 29:  Which of the following is not related to debugging in PHP?
Ans: (B)
Ques 30: Which of the following variable declarations within a class is invalid in PHP?
Ans: (B)
Ques 31:  Which of the following will print out the PHP call stack?
Ans: (B)
Ques 32:  What will be the output of the following code?
<?php echo 30 * 5 . 7; ?>
Ans: (B)
Ques 33:  What is wrong with the following code?
Ans: (D)
Ques 34:  Which of the following is not a valid API?
Ans: (A)
Ques 35:  Without introducing a non-class member variable, which of the following can be used to keep an eye on the existing number of objects of a given class?
Ans: (C) (D)
Ques 36:  <?php $arr = array(“foo”,              “bar”,              “baz”); for ($i = 0; $i < count($arr); $i++) {    $item = $arr[$i];  } echo “<pre>”; print_r($item); echo “</pre>”; ?>
Ans: (D)
Ques 37:  Which is true about the curl_setopt() API?
Ans:  (D) (B)
Ques 38:  What will be the output of following code?  $a = 10; echo “Value of a = $a”;
Ans:  (A)
Ques 39:  Consider the following class:  1  class Insurance 2  { 3      function clsName() 4      { 5          echo get_class($this); 6      } 7  } 8  $cl = new Insurance(); 9  $cl->clsName(); 10 Insurance::clsName();  Which of the following lines should be commented to print the class name without errors?
Ans: (B)
Ques 40:  Which of the following will return the extension of a file name?
Ans: (C)

Ques 41:  Que: <?php $str=”Hello”;  $test=”lo”;  echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;  ?>
Ans: (D)
Ques 42:  Which of the following is not a valid API?
Ans:  (A)
Ques 43:  <?php   $string1 = “abcdefg”;   $string2 = “abcfghi”;   $position = strspn($string1 ^ $string2, “\0″);   echo $position; ?>
Ans:  (C)
Ques 44:  Which of the following will print out the PHP call stack?
Ans:  (B)
Ques 45:  What is the correct way to count the number of parameters given in the URL by a post operation?
Ans: (C)
Ques 46:  What is the meaning of the system message, “Allowed memory size of <number> bytes exhausted”?
Ans: (D)
Ques 47:  Which of the following cryptographic functions in PHP returns the longest hash value?
Ans: (B)
Ques 48:  What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.
Ans: (F)
Ques 49:  which of the following will print out the php call stack
Ans: (B)
Ques 50: which of the following is true about the singleton design pattern
Ans: (B)
1. Question: What is true regarding this code?
Answer: setcookie will return true
2. Question: Which of the following is not a correct way of printing text in php5?
Answer: echo “Plain text”;
3. Question: Which of the following is not the correct way of starting a session?
Answer: session_initiate()
4. Question: Which of the following functions do you need to implement HTTP Basic Authentication?
Answer: None of the above
5. Question: Which of the following Command Line Interface constant is not defined in the CLI SAPI?
Answer: STDPRT
6. Question: Which of the following statements is correct with regard to final and abstract?
Answer: a. An abstract class cannot have final methods
7. Question: Which composite data types are supported by php?
Answer: Array
8. Question: The default value of register_globals in PHP is:
Answer: Off
9. Question: Which of the following is not a valid PHP connection status?
Answer: open
10. Question: Choose the correct statement:
Answer: include() includes and evaluates a specific file
require_once() includes and evaluates a specific file only if it has not been included before
11. Question: If the session_cache_expire() is not set, then by default the session cache will expire after:
Answer: 3 hrs
12. Question: What will be the output of the following script?
$count=50;
Paamayim Nekudotayim operator allows access only to the static members of a class?
Paamayim Nekudotayim operator allows access only to the static members of a class?
Answer: function_exists
$i=4;
User Name:
Password:
class Manager{
Answer: 5+2 * 4+6
$var = 1 + “-1.3e3″;
function Argument()
{
$count++;
echo $count;
}
Argument();
?>
Answer: It will print 1
13. Question: State whether True or False
Answer: True
14. Question: Which of the following statements is true with regard to comparisons in PHP5?
Answer: With (===) operator, object variables are identical if and only if they refer to the same instance of the same class.
15. Question: What will be the output of the following code?
$a = 0.0;
for ($i = 0; $i < a ="="">
Answer: 1
16. Question: What will be the output of the following code?
$j=30;
$k=0;
$k=$j++/$i++;
echo $i . ” ” . $j . ” ” . $k . ” “;
Answer: 5 31 7.5
17. Question: Which of the following is a not a correct way of commenting in php?
Answer: /#PHP Comment
18. Question: Following is a php code block:
$m=9;
$n=99;
$z=8;
$z=$n++/$m++ + –$z;
echo $z;
what will be the output?
Answer: 18
19. Question: Which of the following is the correct way of specifying default value?
Answer: function GetDiscount($Type = “Special”) { . . . }
20. Question: With reference to the following php script:
print ‘Text Line1′
print ‘Text Line2′
?>
What will be the output on running the script?
Answer: Error message will be printed
21. Question: What will be the ouput of the following code?
for ($i = 0; $i < i ="="">
0134
Question: Late PHP versions support remote file accessing for the functions:
Answer: include_once()
require_once()
both of them
22. Question: You have designed a user login form as follows:
How can you access the username entered by the user in the ‘Validate.php’ webpage?
a. $var= $_POST['username'];
b. $var= $_REQUEST['username'];
c. import_request_variables(‘p’, ‘p_’);
$var= $p_username;
Answer: Both of them
23. Question: Which of the following does not represent logical AND operator in PHP?
Answer: &amp
24. Question: Which of the following is not true for a persistent connection?
Answer: These can’t be converted to non-persistent connections
25. Question: Which of the following are invalid data types in PHP?
Answer: char
26. Question: The Manager and Office classes are as follows:
function printName() {
echo “Manager”;
}
}
class Office{
function getManager() {
return new Manager();
}
}
$ofc = new Office();
???
?>
Which of the following should replace ‘???’ to obtain the value of printName() function?
Answer: $ofc->getManager()->printName();
27. Question: The classes are defined as follows:abstract class BaseCls{
protected abstract function getName();
}
class ChildCls extends BaseCls{
}
Which of the following implementations of getName() is invalid in ChildCls?
Answer: public function getName(){}
28. Question: Which of the following variable declarations within a class is invalid in PHP5?
Answer: var $term =3;
29. Question: What will be the output of following code?
$arr = “a”;
$arr[0]=”b”;
echo $arr;
echo $arr[0];
Answer: bb
30. Question: For the following code:
the output will be:
Answer: 171
31. Question: What is the result of the following expression?
Question: What will be the output of following code?
echo $var;
Answer: -1299
32. Question: What will be the output of following code?
$var1=”a”;
$$var1=”b”;
echo “$var1 $a”;
Answer: a b
33. Question:What is the output of the following code?
$a = 500;
$b = 200;
echo $a % 2
* $b;
?>
Answer: 0
34. Question: What will be the ouput of the following code?
if (-1)
print “true”;
else
print “false”;
?>
Answer: true
35. Question: What will be the output of the following code?
echo 12 . 6;
Answer: 126

36. Question: Consider the following sample code:
$x = 0xFFFE;
$y = 2;
$z = $x && $y;
What will be the value of $z?
Answer: 1
 
Question 1:
What will be the result of following operation?
Print 4<<5;
  1. 3
  2. 128
  3. 120
  4. 6
Answer is:       120

Question 2:
You wrote following script to check for the right category:
  1. 2
  2. $cate=5;
  3. ...
  4.  
  5. if ($cate==5)
  6. {
  7. ?>
  8. Correct category!
  9. 11 }
  10. else {
  11. ?>
  12. Incorrect category!
  13. 15 }
  14. }
  15. ?>
What will be the output of the program if value of ‘cate’ remains 5?
  1. Correct category!
  2. Incorrect category!
  3. Error due to use of invalid operator in line 6:”if ($cate==5)”
  4. Error due to incorrect syntax at line 8, 10, 12 and 14
Answer is:       Correct category!

Question 3:
You need to count the number of parameters given in the URL by a POST operation. The correct way is:
  1. count($POST_VARS);
  2. count($POST_VARS_PARAM);
  3. count($_POST);
  4. count($HTTP_POST_PARAM);
Answer is:       count($_POST);

Question 4:
If expire parameter of setCookie function is not specified then:
  1. Cookie will never expire.
  2. Cookie will expire with closure of the browser
  3. Cookie will expire with within 30 minutes
  4. Cookie will expire in 24 hours
Answer is:       Cookie will expire with closure of the browser

Question 5:
Which of the following variables declarations within a class is invalid in PHP5?
  1. Private $type = ‘moderate’;
  2. Internal $term =3;
  3. Public $name =’500’;
  4. Protected $name = ‘Quantas Private Limited’;
Answer is:       Protected $name = ‘Quantas Private Limited’;

Question 6:
Which of the following statements is not true with regard to abstract classes in PHP5?
  1. Abstract classes are introduced in PHP5
  2. A class with a single abstract method must be declared abstract
  3. Abstract class can contain non abstract methods
  4. Abstract method must have method definition and can have optional empty braces following it
Answer is:       Abstract method must have method definition and can have optional empty braces following it

Question 7:
Which of the following pair have non-associative equal precedence?
  1. +,-
  2. ==, !=
  3. <<, >>
  4. &=, |=
Answer is:       &=, |=empty braces following it

Question 8:
You have two strings, which you want to concatenate.
$str1 = ‘Have a ‘;
$str2 = ‘Nice Day’;
The fastest way would be:
  1. $str1. Concat($str2);
  2. $str1. $str2;
  3. “$str1$str2”;
  4. None of the above
Answer is:       None of the above

Question 9:
For the following code:
  1. Function Expenses()
  2. {
  3. Function Salary()
  4. {
  5. }
  6. Function Loan()
  7. {
  8. Function Balance()
  9. {
  10. }
  11. }
  12. ?>
Which of the following sequence will run successfully?
  1. Expenses();Salary();Loan();Balance();
  2. Salary();Expenses();Loan();Balance();
  3. Expenses();Salary();Balance();Loan();
  4. Balance();Loan();Salary();Expenses();
Answer is:       Salary();Expenses();Loan();Balance();

Question 10:
Which of the following is not supported in PHP5?
  1. Type Hinting
  2. Reflection
  3. Magic Methods         
  4. Multiple Inheritance
  5. Object Cloning
Answer is:       Multiple Inheritance

Question 11:
How would you start a session?
  1. Session(start);
  2. Session();
  3. Session_Start();
  4. Begin_sesion();
Answer is:       Session_Start();

Question 12:
What do you infer from the following code?
$str=’Dear Customer,\nThanks for your query. We will reply very soon.?\n Regards.\n Customer Service Agent’: Print $str;
?>
  1. Only first\n Character will be recognized and new line will be inserted.
  2. Last \n Will not be recognized and only first two parts will come in new lines.
  3. All the \n Will work and text will be printed on respective new lines.
  4. All will be printed on one line irrespective of the \n.
Answer is:       All the \n Will work and text will be printed on respective new lines.  

Question 13:
What will be the result of the following expression:
6+4*9-3
  1. 60
  2. 87
  3. 39
  4. 30
Answer is:       87

Question 14:
What is true regarding $a+$b where both of them are arrays?
  1. Duplicated keys are NOT overwritten
  2. 87
  3. The + operator is overloaded
  4. This produces a syntax error
Answer is:       $b is appended to $a

Question 15:
Which of the following characters are taken care of by html special chars?
  1. <
  2. >
  3. Single quote
  4. Double Quote
  5. &
  6. All of the above
Answer is:       >

Question 16:
The value of a local variable of a function has to be retained over multiple calls to that function. How should that variable be declared?
  1. Local
  2. Global
  3. Static
  4. None of the above
Answer is:       Static

Question 17:
Which of the following multithreaded servers allow PHP as a plug-in?
  1. Netscape FastTrack
  2. Microsoft’s Internet Information Server
  3. O’Reilly’s WebSite Pro
  4. All of the above
Answer is:       All of the above

Question 18:
Multiple select/load is possible with:
  1. Checkbox
  2. Select
  3. File
  4. All of the above
Answer is:       All of the above

Question 19:
Which of the following variable names are invalid?
  1. $var_1
  2. $var1
  3. $var-1
  4. $var/1
  5. $v1
Answer is:       $var1

Question 20:
Which of the following are useful for method overloading?
  1. _call,_get,_set
  2. _get,_set,_load
  3. _get,_set,_load
  4. _overload
Answer is:       _get,_set,_load

Question 21:
What will be the output of the following code?
Function fn(&$var)
{
$var=$var-($var/10*5);
Return $var;
}
Echo fn(100);
  1. 100
  2. 50
  3. 98
  4. Error message
  5. None of the above
Answer is:       None of the above

Question 22:
Which of the following type cast is not correct?
  1. $fig=23;
  2. $varb1 = (real) $fig;
  3. $varb2 = (double) $fig;
  4. $varb3 = (decimal) $fig;
  5. $varb4 = (bool) $fig;
  6. ?>
  1. Real
  2. Double
  3. Decimal
  4. Boolean
Answer is:       Double

Question 23:
What will be the output of following code?
$a = 10;
Echo “value of a = $a”;
  1. Value of a = 10
  2. Value of a = $a
  3. Undefined
  4. Syntax Error
Answer is:       Value of a = $a

Question 24:
What will be the output of following code?
$var = 10;
Function fn()
{
$var = 20;
Return $var;
}
Fn();
Echo $var;
  1. 10
  2. 20
  3. Undefined Variable
  4. Syntax Error
Answer is:       Syntax Error

Question 25:
Which of the following attribute is needed for file upload via form?
  1. Enctype=”multipart/form-data”
  2. Enctype=”singlepart/data”
  3. Enctype=”file”
  4. Enctype=” form-data/file”
Answer is:       Enctype=”file”

Question 26:
Which of the following is not a file related function in PHP?
  1. Fclose
  2. Fopen
  3. Fwrite
  4. Fgets
  5. Fappend
Answer is:       Fgets

Question 27:
Which of the following is correct with regard to echo and print?
  1. Echo is a construct and print is a function
  2. Echo is a function and print is a construct
  3. Both are functions
  4. Both are constructs
Answer is:       Echo is a function and print is a construct

Question 28:
Which of the following is a correct declaration?
  1. Static $varb = array(1,’val’,3);
  2. Static $varb = 1+(2*90);
  3. Static $varb = sqrt(81);
  4. Static $varb = new object;
Answer is:       Static $varb = new object;

Question 29:
Consider the following two statements:
I.          While (expr) statement
II.         While (expr): statement…endwhile;
Which of the following are true in context of the given statements?
  1. I is correct and II is wrong
  2. I is wrong and II is correct
  3. Both I & II are wrong
  4. Both I & II are correct
Answer is:       I is wrong and II is correct

Question 30:
You are using sessions and session register() to register objects. These objects are serialized automatically at the end of each PHP page and are de-serialized automatically on each of the following pages. Is this true of false?
  1. True
  2. False
Answer is:       True
 
?>
a.    1 (Answer)
b.    Syntax error
c.    0

Question:
What does the array_combine (a, b) function do?
a.    It appends b to a
b.    It associates all keys of a with the values of b and returns a new array
c.    It returns a new array with all values of b added to the values of a
d.    It doesn’t exist
e.    None of the above   (Answer)
Question:
What will be the output of the following code?
$a = “print”;
$a (“hello”);
?>
a.    print
b.    hello
c.    print hello
d.    fatal error   (Answer)
e.    None of the above
Question:
What is the precedence between && and “and”?
a.    && is higher than “and”   (Answer)
b.    “and” is higher than &&
c.    They have the same precedence
d.    Those operators don’t exist
Question:
What will be the output of the following code?
echo false;
?>
a.    0
b.    false
c.    FALSE
d.    Nothing (Answer)
e.    Syntax error
Question:
Which of the following is the operator with the highest precedence?
a.    +
b.    instanceof
c.    new (Answer)
d.    =
e.    None of the above
Question:
What is “?:”  ?
a.    A logical operator
b.    A comparison operator
c.    A ternary operator  (Answer)
d.    A bitwise operator
e.    None of the above
Question:
What is the string concatenation operator in PHP?
a.    +
b.    ||
c.    . (dot)  (Answer)
d.    |||
e.    None of the above
Question:
Is the PHP float type guaranteed to be 64 bit IEEE?
a.    yes (Answer)
b.    no
Question:
Which of the following is the operator with the lowest precedence?
a.    new
b.    and
c.    , (comma) (Answer)
d.    =
Question:
Which statement will return true?
a.    is_numeric (“200″)  (Answer)
b.    is_numeric (“20,0″)
c.    is_numeric (“$200″)
d.    is_numeric (“.25e4″)  (Answer)
e.    None
Question:
What will be the output of the following code?
print null == NULL;
?>
a.    1 (Answer)
b.    0
Question:
What is the output of the following code?
echo 0×500;
?>
a.    500
b.    0×500
c.    0500
d.    1280  (Answer)
e.    320
Question:
When comparing two arrays, what is the difference between == and === ?
a.    == compares keys while === compares keys and values
b.    === also compares the order and types of the objects
c.    === compares the array references
d.    They are identical   (Answer)
e.    None of the above
Question:
What is the initial value of a variable?
a.    0
b.    “0″
c.    NULL  (Answer)
d.    Any value
Question:
What will be the output of the following code?
$a = 3;
print ‘$a’;
?>
a.    3
b.    $a   (Answer)
c.    Syntax error
d.    None of the above
Question:
With the following code, will the word Hello be printed?
//?>Hello
a.    yes  (Answer)
b.    no
Question:
What will be the output of the following code?
$s = “Hello world!”;
print $s[4];
?>
a.    H
b.    e
c.    l
d.    o  (Answer)
e.    ” ” (a space)
Question:
What is the output of the following code?
$a = (1 << 0);
$b = (1 << 1);
echo $b | $a;
?>
a.    0
b.    1
c.    2
d.    3  (Answer)
e.    8
f.    32
g.    Syntax error
Question:
What will be the output of the following code?
echo “5.0″ == “5″;
?>
a.    0
b.    1  (Answer)
c.    5.0
d.    Syntax error
e.    None of the above
Question:
What function should you use to join array elements with a glue string?
a.    join_str
b.    implode (Answer)
c.    connect
d.    make_array
e.    None of the above
Question:
What is the output of the following code?
echo (2) . (3 * (print 3));
?>
a.    233
b.    29
c.    329
d.    323  (Answer)
e.    Syntax error
Question:
How can you check if a function exists?
a.    With function_exists function  (Answer)
b.    With has_function function
c.    With $a = “function to check”; if ($a ()) // then function exists
d.    It can’t be done
e.    None of the above
Question:
What is the output of the following code?
$a = 0;
echo ~$a;
?>
a.    -1  (Answer)
b.    0
c.    1
d.    10
e.    Syntax error
Question:
What is the associativity of +=?
a.    left
b.    right
c.    it is non-associative  (Answer)
Question:
With what encoding does chr () work?
a.    ASCII
b.    UTF-8   (Answer)
c.    UTF-16
d.    Implementation dependent
e.    None of the above
Question:
Will the trim function strip NULL bytes?
a.    Yes
b.    No   (Answer)
Question:
Which of the following is a type of array in PHP?
a.    string
b.    compound
c.    callback
d.    scalar
e.    struct  (Answer)
Question:
What will be the output of the following code?
$a = 0×01;
$b = 0×02;
echo $a === $b >> $a;
?>
a.    0
b.    1  (Answer)
c.    Syntax error
Question:
Can feof () be used with a file opened by fsockopen () ?
a.    yes
b.    no  (Answer)
Question:
Knowing that the output of the first echo is “2.5″, what will be the output of the third one?
setlocale(LC_ALL, “fr_FR”);
echo (string)2.5;
echo “\n”;
echo (float)(string)2.5;
?>
a.    2.5 (Answer)
b.    25
c.    2,5
d.    2
e.    Syntax error
Question:
What function will you use to remove the first element of an array?
a.    array_remove_first_element
b.    array_shift    (Answer)
c.    array_ltrim
d.    a[0] = nil
e.    None of the above
Question:
What will be the output of the following code?
$a = “Hello”;
if (md5($a) === md5($a))
print “True”;
else
print “False”;
?>
a.    True  (Answer)
b.    False
Question:
What does the array_unshift () function do?
a.    It shifts an element off the beginning of array
b.    It shifts all bits of the array to the left
c.    It undo what array_shift does
d.    None of the above   (Answer)
Question:
Should assert () be used to check user input?
a.    yes  (Answer)
b.    no
Question:
In the following list, which one is not a string literal definition?
a.    single quoted
b.    heredoc syntax
c.    nowdoc syntax
d.    double quoted
e.    All are string literals  (Answer)
Question:
What will be the output of the following code?
$a = “NULL”;
echo !empty ($a);
?>
a.    0
b.    1  (Answer)
c.    TRUE
d.    FALSE
e.    NULL
Question:
What will be the output of the following code?
$foo = 5 + “10 things”;
print $foo;
?>
a.    510 things
b.    5 10 things
c.    15 things
d.    15   (Answer)
e.    None of the above
Question:
What will be the output of the following code?
$a = (1 << 0);
$b = (1 << $a);
$c = (1 << $b);
echo ($c || $b) << 2 * $a | $a;
?>
a.    1
b.    3
c.    5  (Answer)
d.    12
e.    27
f.    32
g.    Syntax error
Question:
Which fopen option opens the file for reading and writing; placing the file pointer at the beginning of the file without truncating it.
a.    r
b.    r+
c.    w
d.    W+
e.    a
Question:
What is the output of the following code?
echo  0500;
?>
a.    100
b.    500
c.    0500
d.    320
e.    None of the above  (Answer)
Question:
What is the size limit of strings in php?
a.    1024bytes
b.    100Mbytes
c.    256Kbytes
d.    There is no limit (hardware limit)   (Answer)
e.    None of the above
Question:
What kind of regular expression does PHP include?
a.    PCRE
b.    Java REGEX
c.    Ruby REGEX
d.    None of the above  (Answer)
Question:
What is the output of the following code?
echo ’1′.print(2) + 3;
a.    123
b.    321
c.    511  (Answer)
d.    155
e.    432
Question:
Is the following code valid?
$a = 5;
if ($a == 5):
echo “Hello”;
echo “1″;
else:
echo “Not hello”;
echo “2″;
endif;
?>
a.    yes  (Answer)
b.    no
Question:
Can PHP use Gettext?
a.    yes  (Answer)
b.    no
Question:
What will be the output of the following code on a machine using IEEE 754 floats?
print (19.6*100) !== (double)1960;
?>
a.    0
b.    1  (Answer)
c.    Nothing
d.    Syntax error
Question:
What will be the output of the following code?
$a = 3;
print ‘$a’;
?>
a.    3
b.    $a  (Answer)
c.    Syntax error
d.    None of the above
Question:
What will be the output of the the following code?
echo !!!0;
?>

a.(Answer)

b.Syntax error

c.0
 Question:
What does the array_combine (a, b) function do?

a.It appends b to a

b.It associates all keys of a with the values of b and returns a new array

c.It returns a new array with all values of b added to the values of a

d.It doesn’t exist

e.None of the above   (Answer)
 Question:
What will be the output of the following code?
$a = “print”;
$a (“hello”);
?>

a.print

b.hello

c.print hello

d.fatal error   (Answer)

e.None of the above
 Question:
What is the precedence between && and “and”?

a.&& is higher than “and”   (Answer)

b.“and” is higher than &&

c.They have the same precedence

d.Those operators don’t exist
 Question:
What will be the output of the following code?
echo false;
?>

a.0

b.false

c.FALSE

d.Nothing (Answer)

e.Syntax error
 Question:
Which of the following is the operator with the highest precedence?

a.+

b.instanceof

c.new (Answer)

d.=

e.None of the above
 Question:
What is “?:”  ?

a.A logical operator

b.A comparison operator

c.A ternary operator  (Answer)

d.A bitwise operator

e.None of the above
 Question:
What is the string concatenation operator in PHP?

a.+

b.||

c.. (dot)  (Answer)

d.|||

e.None of the above
 Question:
Is the PHP float type guaranteed to be 64 bit IEEE?

a.yes (Answer)

b.no
 Question:
Which of the following is the operator with the lowest precedence?

a.new

b.and

c., (comma) (Answer)

d.=
 Question:
Which statement will return true?

a.is_numeric (“200″)  (Answer)

b.is_numeric (“20,0″)

c.is_numeric (“$200″)

d.is_numeric (“.25e4″)  (Answer)

e.None
 Question:
What will be the output of the following code?
print null == NULL;
?>

a.1 (Answer)

b.0
 Question:
What is the output of the following code?
echo 0×500;
?>

a.500

b.0×500

c.0500

d.1280  (Answer)

e.320
 Question:
When comparing two arrays, what is the difference between == and === ?

a.== compares keys while === compares keys and values

b.=== also compares the order and types of the objects

c.=== compares the array references

d.They are identical   (Answer)

e.None of the above
 Question:
What is the initial value of a variable?

a.0

b.“0″

c.NULL  (Answer)

d.Any value
 Question:
What will be the output of the following code?
$a = 3;
print ‘$a’;
?>

a.3

b.$a   (Answer)

c.Syntax error

d.None of the above
 Question:
With the following code, will the word Hello be printed?
//?>Hello

a.yes  (Answer)

b.no
 Question:
What will be the output of the following code?
$s = “Hello world!”;
print $s[4];
?>

a.H

b.e

c.l

d.o  (Answer)

e.” ” (a space)
 Question:
What is the output of the following code?
$a = (1 << 0);
$b = (1 << 1);
echo $b | $a;
?>

a.0

b.1

c.2

d.3  (Answer)

e.8

f.32

g.Syntax error
 Question:
What will be the output of the following code?
echo “5.0″ == “5″;
?>

a.0

b.1  (Answer)

c.5.0

d.Syntax error

e.None of the above
 Question:
What function should you use to join array elements with a glue string?

a.join_str

b.implode (Answer)

c.connect

d.make_array

e.None of the above
 Question:
What is the output of the following code?
echo (2) . (3 * (print 3));
?>

a.233

b.29

c.329

d.323  (Answer)

e.Syntax error
 Question:
How can you check if a function exists?

a.With function_exists function  (Answer)

b.With has_function function

c.With $a = “function to check”; if ($a ()) // then function exists

d.It can’t be done

e.None of the above
 Question:
What is the output of the following code?
$a = 0;
echo ~$a;
?>

a.-1  (Answer)

b.0

c.1

d.10

e.Syntax error
 Question:
What is the associativity of +=?

a.left

b.right

c.it is non-associative  (Answer)
 Question:
With what encoding does chr () work?

a.ASCII

b.UTF-8   (Answer)

c.UTF-16

d.Implementation dependent

e.None of the above
 Question:
Will the trim function strip NULL bytes?

a.Yes

b.No   (Answer)
 Question:
Which of the following is a type of array in PHP?

a.string

b.compound

c.callback

d.scalar

e.struct  (Answer)
 Question:
What will be the output of the following code?
$a = 0×01;
$b = 0×02;
echo $a === $b >> $a;
?>

a.0

b.1  (Answer)

c.Syntax error
 Question:
Can feof () be used with a file opened by fsockopen () ?

a.yes

b.no  (Answer)
 Question:
Knowing that the output of the first echo is “2.5″, what will be the output of the third one?
setlocale(LC_ALL, “fr_FR”);
echo (string)2.5;
echo “\n”;
echo (float)(string)2.5;
?>

a.2.5 (Answer)

b.25

c.2,5

d.2

e.Syntax error
 Question:
What function will you use to remove the first element of an array?

a.array_remove_first_element

b.array_shift    (Answer)

c.array_ltrim

d.a[0] = nil

e.None of the above
 Question:
What will be the output of the following code?
$a = “Hello”;
if (md5($a) === md5($a))
print “True”;
else
print “False”;
?>

a.True  (Answer)

b.False
 Question:
What does the array_unshift () function do?

a.It shifts an element off the beginning of array

b.It shifts all bits of the array to the left

c.It undo what array_shift does

d.None of the above   (Answer)
 Question:
Should assert () be used to check user input?

a.yes  (Answer)

b.no
 Question:
In the following list, which one is not a string literal definition?

a.single quoted

b.heredoc syntax

c.nowdoc syntax

d.double quoted

e.All are string literals  (Answer)
 Question:
What will be the output of the following code?
$a = “NULL”;
echo !empty ($a);
?>

a.0

b.1  (Answer)

c.TRUE

d.FALSE

e.NULL
 Question:
What will be the output of the following code?
$foo = 5 + “10 things”;
print $foo;
?>

a.510 things

b.5 10 things

c.15 things

d.15   (Answer)

e.None of the above
 Question:
What will be the output of the following code?
$a = (1 << 0);
$b = (1 << $a);
$c = (1 << $b);
echo ($c || $b) << 2 * $a | $a;
?>

a.1

b.3

c.5  (Answer)

d.12

e.27

f.32

g.Syntax error
 Question:
Which fopen option opens the file for reading and writing; placing the file pointer at the beginning of the file without truncating it.

a.r

b.r+

c.w

d.W+

e.a
 Question:
What is the output of the following code?
echo  0500;
?>

a.100

b.500

c.0500

d.320

e.None of the above  (Answer)
 Question:
What is the size limit of strings in php?

a.1024bytes

b.100Mbytes

c.256Kbytes

d.There is no limit (hardware limit)   (Answer)

e.None of the above
 Question:
What kind of regular expression does PHP include?

a.PCRE

b.Java REGEX

c.Ruby REGEX

d.None of the above  (Answer)
 Question:
What is the output of the following code?
echo ’1′.print(2) + 3;

a.123

b.321

c.511  (Answer)

d.155

e.432
 Question:
Is the following code valid?
$a = 5;
if ($a == 5):
echo “Hello”;
echo “1″;
else:
echo “Not hello”;
echo “2″;
endif;
?>

a.yes  (Answer)

b.no
 Question:
Can PHP use Gettext?

a.yes  (Answer)

b.no
 Question:
What will be the output of the following code on a machine using IEEE 754 floats?
print (19.6*100) !== (double)1960;
?>

a.0

b.1  (Answer)

c.Nothing

d.Syntax error
 Question:
What will be the output of the following code?
$a = 3;
print ‘$a’;
?>

a.3

b.$a  (Answer)

c.Syntax error

d.None of the above
 
Question: You have two strings, which you want to concatenate.

$str1 = ‘Have a ‘;
$str2 = ‘Nice Day’;
The fastest way would be:

a. $str1.Concat($str2);
b. $str1.$str2;
c. “$str1$str2”;
d. None of the above


Question:Which of the following variables is not related to file uploads?

a. max_file_size
b. max_execution_time
c. post_max_size
d. max_input_time

Question: You have a 2D array in PHP:

$array = array(array(141,151,161), 2,3, array(101, 202, 303));
You want to display all the values in the array The correct way is:

a.
function DisplayArray($array) {
   foreach ($array as $value) {
      if (array_valid($value)) {
         DisplayArray($value);
      } else {
         echo $value. “<br>”;
      }
   }
}

DisplayArray($array);
b.
function DisplayArray($array) {
   for ($array as $value) {
      if (valid_array($value)) {
         DisplayArray($value);
      } else {
         echo $value. “<br>”;
      }
   }
}

DisplayArray($array);
c.
function DisplayArray($array) {
   for ($array as $value) {
      if (is_array($value)) {
         DisplayArray($value);
      } else {
         echo $value. “&ltbr>”;
      }
   }
}

DisplayArray($array);
d.
function DisplayArray($array) {
   foreach ($array as $value) {
      if (is_array($value)) {
         DisplayArray($value);
      } else {
         echo $value “&ltbr>”;
      }
   }
}

DisplayArray($array);
Right answer: d.

Question: Multiple select/load is possible with:

a. Checkbox
b. Select
c. File
d. All of the above

Question: The following php variables are declared:

$company = ‘ABS Ltd’;
$$company =‘, Sydney’;
Which of the following is not a correct way of printing ‘ABS Ltd. Sydney’?

a. echo “$company $$company”;
b. echo “$company ${$company}”;
c. echo “$company ${‘ABS Ltd‘}“;
d. echo “$company {$$company}”;

Question (many answers)
We have two variable definitions:
1. 023
2. x23
Choose the correct options:

a. 1 is octal
b. 2 is hexadecimal
c. 2 is octal
d. 1 is hexadecimal

Question: Which of the following is a predefined constant?

a. TRUE
b. FALSE
c. NULL

e. CONSTANT

Question (many answers): Which of the following variable names are invalid?

a. $var_1
b. $var1
c. $var-1
d. $var/1
e. $vl

Question (many answers): Which of the following are not considered as boolean False?

a. FALSE
b. 0
c. “0”
d. “FALSE”
e. 1
f. NULL

Question: Which of the following regular expressions can be used to check the validity of an e-mail addresss?

a. ^[^@ ]+@[^@ ]+\.[“@ ]+$
b. ^[^@ ]+@[^@ ]+[^@ ]+$
c. $[^@ ]+@[^@ ]+\[^@ ]+^
d. $[^@ ]+@[^@ ]+[^@ ]+^

Question: Which of the following type cast is not correct?

$fig=23;
$varbl= (real) $fig;
$varb2 = (double) $flg;
$varb3 = (decimal) $flg;
$varb4 = (bool) $fig;

a. real
b. double
c. decimal
d. boolean

Question: Which of the following statements is not true with regard to abstract classes in php5?

a. Abstract classes are introduced in PHP5
b. A class with a single abstract method must be declared abstract
c. Abstract class can contain non abstract methods
d. Abstract method must have method definition and can have optional empty braces following it

Question: What do you infer from the following code?

$str = ‘Dear Customer,\nThanks for your query. We will reply very soon\n Regards,\n Customer Service Agent’;
print $str;

a. Only first \n character will be recognised and new line will be inserted
b. Last \n will not be recognised and only first two parts will come in new lines
c. All the \n will work and text will be printed on respective new lines.
d. All will be printed on one line irrespective of the \n.

Question: Which of the following characters are taken care of by htmlspecialchars?

a. <
b. >
c. single quote
d. double quote
e. &
f. All of the above

Question: What will be the output of the following code?

$a = 10;
if($a > 5 OR < 15)
echo “true”;
else
echo “false”

a. true
b. false
c. No output
d. Parse Error

Question: If expire parameter of setCookie function is not specified then:

a. Cookie will never expire
b. Cookie will expire with closure of the browser
c. Cookie will expire with within 30 minutes
d. Cookie will expire in 24 hours

3 hrs by default.

Question: You need to check the size of a file in PHP function.

$size=X(filename);
Which function will suitably replace ‘X’ ?

a. filesize
b. size
c. sizeofFile
d. getSize

Question: Which of the following text manipulation functions is supported by PHP?

a. strtoupper()
b. ucfirst()
c. strtolower()
d. str_split()
e. All of the above

Question: Which of the following is a correct declaration?

a. static $varb = array(1 ,‘var, 3);
b. static $varb = 1+(2*9O);
c. static $varb = sqrt(81);
d. static $varb = new Object;

Question: You wrote following script to check for the right category:

<?php
$cate=5;
if ($cate==5)
{
?>
Correct category!
<?php
} else {
?>
Incorrect category!
<?php
}
?>

What will be the output of the program if value of’cate’ remains 5?

a. Correct category!
b. Incorrect category!
c. Error due to use of invalid operator in line 6:”if ($cate=5)»
d. Error due to incorrect syntax at line 8, 10, 12 and 14

Question: If visibility is not defined for a method/member then it is treated as public static.

a. True
b. False

Question (many answers): Which of the following statements is incorrect with regard to interfaces?

a. A class can implement multiple interfaces
b. An abstract class cannot implement multiple interlaces
c. An interlace can extend multiple interfaces
d. Methods with same name, arguments, and sequence can exist in the different interlaces implemented by a class

Question: Which of the following is a Ternary Operator?

a. &
b. =
c. : ?
d. ? :
e. +=
f. &&

Question: Which of the following are the valid PHP data types?

a. resource
b. null
c. boolean
d. string
e. Both a and c

g. All of the above 

Question: You are using sessions and session_register() to register objects. These objects are serialized automatically at the end of each PHP page and are de-serialized automatically on each of the following pages Is this true or false?

a. True

Question: What will be the output of the following code?

$Rent = 250;
function Expenses($Other) {
   $Rent = 250 + $Other;
   return $Rent;
}

Expenses(50),
echo $Rent;
a. 300
b. 250
c. 200
d. Program will not compile

Question: What will be the result of the following expression:

6+4 * 9-3

a. 60
b. 87
c. 39
d. 30

Question: Does php 5 support exceptions?

a. Yes
b. No

Question (many answers): Which of the following printing construct/function accepts multiple parameters?

a. echo
b. print
c. printf
d. Allof the above

Question: What will be the output of the following code?

$var = 10;
function fn() {
   $var=20;
   return $var;
}

Fn();
echo $var;

a. 10
b. 20
c. Undefined Variable
d. Syntax Error

Question: Which of the following is not true regarding XForms?

a. PHP provides support for XForm
b. It can be used on PDF documents
c. The data is sent in XML format
d. The action and method parameters are defined in the body

Question: How would you start a session?

a. session(start);
b. session();
c. session_start();
d. begin_sesion();

Question: How would you store order number (34) in an OrderCookie’?

a. setcookie(«OrderCookie”, 34);
b. makeCookie(”OrderCookie”, 34);
c. Cookie(«OrderCookie”, 34);
d. OrderCookie(34);

Question: What will be the output of the following code?

function fn(&$var) {
   $var = $var - ($var/l0*5);
   return $var;
)
echo fn(100);

a.100
b. 50
c. 98
d. Error message
e. None of the above

Question: What will be the result of following operation?

print 4 << 5;
a. 3
b. 128
c. 120
d. 6

Question: Which of the following is not supported in PHP5?

a. Type Hinting
b. Reflection
c. Magic Methods
d. Muftiple Inheritance
e. Object Cloning

Question: Which of the following is not a valid PHP parser tag?

b. ?p
c. %
d. ?php

Question: What will be the output of following code?

$a=10;
echo “Value of a =$a”;

a. Value of a=10
b. Value of a=$a
c. Undefined
d. Syntax Error

Question: You need to keep an eye on the existing number of objects of a given class without introducing a non-class member variable.Which of the following makes this happen?

a. Add a member variable that gets incremented in the default constructor and decremented in the destructor
b. Add a local variable that gets incremented in each constructor and decremented in the destructor
c. Add a static member variable that gets incremented in each constructor and decremented in the destructor
d. This cannot be accomplished since the creation of objects is being done dynamically via “new”

Question: Which of the following multithreaded servers allow PHP as a plug-in?

a. Netscape FastTrack
b. Microsoft’s Internet Information Server
c. O’Reilly’s WebSite Pro
d. Allof the above

Question: Which of the following is used to maintain the value of a variable over different pages?

a. static
b. global
c. session_register()
d. Noneoftheabove

Question: Which of the following variable declarations within a class is invalid in PHP5?

a. private $type = ‘moderate’;
b. internal $term = 3;
c. public $amnt = ‘500’;
d. protected $name = ‘Quantas Private Limited’;

Question: Consider the following two statements:

1 while (expr) statement
2 while (expr): statement endwhile;
Which of the following are true in context of the given statements?

a. 1 is correct and 2 is wrong

c. Both 1 & 2 are wrong
d. Both 1 & 2 are correct

Question: You have defined three variables $to, $subject, and $body to send an email. Which of the following methods would you use for sending an email?

a. mail($to,$subject,$body)
b. sendmail($to,$subject,$body)
c. mail(to,subject,body)
d. sendmail(to,subject,body)

Question: What is the output of the following code?
function vec_add (&Sa, Sb) {
   $a[X] += $b[’x’];
   $a[y] += $b[’y’];
   $a[Z] += $b['Z'];
}

$a = array (x => 3, y => 2, z => 5);
$b = array (x => 9, y => 3, z => -7);

vec_add (&$a, $b);
print_r ($a);

a. Array
(
[X] => 9
[y] => 3
[Z] => -7
b. Array
[x] => 3
[y] => 2
[z] => 5
c. Array
[xJ =>12
[yJ => 5
[z] => -2
d. Error
e. None of the above

Question (many answers); Which of the the following are PHP file upload related functions?

a. upload_file()
b. is_uploaded_file()
c. move_uploaded_file()
d. Noneoftheabove

Question: Which of the following attribute is needed for file upload via form?

a. enctype=”multipart/formdata”
b. enctype=”singlepart/data’
c. enctype=»file”
d. enctype=»form-data/file”

Question: Variable/functions in PHP don’t work directly with:

a. echo()
b. isset()
c. print()
d. All of the above

Question: Which of the following is a PHP resource?

a. Domxml document
b. Odbc link

d. All of the above 

Question: The inbuilt function to get the number of parameters passed is:

a. arg_num()
b. func_args_count()
c. func_num_args()
d. None of the above

Question: For the following code:

function Expenses() {
   function Salary() {
      function Loan() {
         function Balance() {
         }
      }
   }
}

Which of the following sequence will run successfully?

a. Expenses();Salary();Loan; Balance();
b. Salary();Expenses();Loan(); Balance();
c. Expenses();Salary();Balance();Loan();
d. Balance();Loan();Salary(); Expenses();

Question: What will be the output of the following code?

echo 30 * 5.7

a. 150.7
b. 1507
c. 171
d. you can’t concatenate integers
e. error will occur

Question (many answers): What is true regarding $a + $b where both of them are arrays?

a. Duplicated keys are NOT overwritten
b. $b is appended to $a
c. The + operator is overloadedd. This produces a syntax error

Question: Which of the following pair have non-associative equal precedence?

a. +,-
b. ==,!=
C. «,»
d. &=,|=

Question: What does the array_combine (a, b) function do?

a. It appends b to a
b. It associates all keys of a with the values of b and returns a new array
c. It returns a new array with all values of b added to the values of a
d. It doesn't exist
e. None of the above

Question:  With what encoding does chr () work?

a. ASCII
b. UTF-8
c. UTF-16
d. Implementation dependent
e. None of the above

Question: Which of the following crypto in PHP returns longest hash value?

a. md5()
b. sha1()
c. crc32()
d. All return same length hash

Question: What is the output of the following code?

echo '1'.print(2) + 3;

a. 123
b. 321
c. 511
d. 155
e. 432

Question: Which of the following are useful for method overloading?

a. __call,__get,__set
b. _get,_set,_load
c. __get,__set,__load
d. __overload

Question: What will be the result of following operation?

print 4<< 5;

a. 3
b. 128
c. 120
d. 6

Question: What will be the result of the following expression:

6+4 * 9-3

a. 60
b. 87
c. 39
d. 30

Question: What is the output of the following code?

<?
echo 0500;
?>

a. 100
b. 500
c. 0500
d. 320
e. None of the above
 
 
7 and 12 digits, representing the same phone number after removing all hyphens and spaces. If the phone number is invalid, throw a standard PHP5 Exception initialized with the text “Invalid phone number”.The first and the last character of the string should be a number.
For example, after calling ReformatPhoneNumber(’012-345 69′) the return value should be ’01234569′. Calling the function with any of these values: ’012345′, ‘-012345 678′, ’01203- 34566′, ’123456678875432′, ’1234×567′ should result in an exception.
ANS:
function ReformatPhoneNumber($number)
{
if (preg_match('/^(\d[ -]?){7,12}$/', $number, $matches))
{
return preg_replace('/[ -]/', '', $number);
}

throw new Exception('Invalid phone number');
}
2. Write a program that outputs the numbers that are divisible by 8 and are between 200 and 600 (inclusive), separated by commas (without spaces or line breaks).
ANS:
for($i = 200; $i <= 592; $i+=8)
{
    echo $i.',';
}
echo $i;
3. You are given an array in PHP, which contains positive integers and/or recursively nested arrays of positive integers.
It may, for example, be initialized as:$arr = array(array(141,151,161), 2, 3, array(101, 202, array(303,404)));
Write a function “function MaxArray($arr)” which returns the maximum value contained in $arr or some array nested within $arr. In the example, the returned value should be 404.
ANS:
function MaxArray($arr)
{
    $GLOBALS['max'] = 0;
    array_walk_recursive($arr,create_function('$item,$key','if($item > $GLOBALS["max"]) $GLOBALS["max"] = $item;'));
    return $GLOBALS['max'];
}
4. Write a function ReadXml($xmlstr) which accepts an XML string as its only argument. Your function should write the names of the nodes and their values.
ANS:
function ReadXml($xmlstr)
{
    static $res = '';
    $xml = new SimpleXMLElement($xmlstr);

    if(count($xml->children()))
    {
        $res .= $xml->getName().PHP_EOL;
        foreach($xml->children() as $child)
        {
            ReadXml($child->asXML());
        }
    }
    else
    {
        $res .= $xml->getName().': '.(string)$xml.PHP_EOL;
    }

    return $res;
}
5. Write a function GeneratePassword which accepts two arguments, an integer and a character string consisting of letters (a-z) and digits (0-9).
ANS:
function GeneratePassword ($length,$chars)
{
    $res = '';
    $char_length = strlen($chars);
    for($i = 0; $i < $length; $i++)
    {
        $res .= $chars[rand(0,$char_length)];
    }

    return $res;
}
6. Write a function GetLongestString, whose arguments are character strings. It should return an integer representing the length of the longest string passed as its argument;
for example:
GetLongestString(“a”, “aaa”, “aa”) should return 3,GetLongestString(“a”, “bcd”, “efgh”, “ij”, “”) should return 4.
ANS:
function GetLongestString()
{
    $length = 0;
    foreach(func_get_args() as $arg)
    {

        $var = strlen($arg);
        if($var > $length)
        {
            $length = $var;
        }
    }
    return $length;
}
7. You are given an HTML form, which contains the following entries:
<input type=”checkbox” class=”form” name=”checkbox_2″/>
<input type=”checkbox” class=”form” name=”checkbox_1″/>
<input type=”checkbox” class=”form” name=”checkbox_3″/>

<input type=”checkbox” class=”form” name=”checkbox_10″/>
The form has been submitted using the “POST” method. Identify, which of the check-boxes and write (output) their numbers in increasing order. Separate all numbers by spaces (not new lines) and do not use any HTML formatting.
For example, if check-boxes 3, 5, and 10 are checked, the only valid output would be:3 5 10
ANS:
$res = array();
while(list($checkbox,) = each($_POST))
{
$res[] = intval(substr($checkbox,strpos($checkbox,'_') + 1));
}
sort($res);
echo implode(' ',$res);
8. Write a function GetUniqueOnes, which accepts a single argument. The argument is an array of integers, and the function should return the unique integers separated by commas.
ANS:
function GetUniqueOnes($arr)
{
    $res = implode(',',array_unique($arr));

    return $res;
}
9. Write a function declared as function SplitEmailAddress($address), whose argument will contain string data consisting of a valid e-mail address. This function will take the email address as the argument and return an array with two keys: user for the username part and domain for the domain part of the address. For example, after calling:$arr = SplitEmailAddress(‘myuser_1@mailserver.example.com’) $arr['user'] should contain the string myuser_1, and $arr['domain'] should contain the string mailserver.example.com.
ANS:
function SplitEmailAddress($address)
{
    list($user, $domain) = explode('@',$address);
    return array('user' => $user, 'domain' => $domain);
}
10. Consider a database with one table called “user” having two fields: “id” (type: INTEGER, PRIMARY KEY) “name” (type: VARCHAR(32)) Write a standard SQL query which retrieves the second highest value of “id” from the “user” table. The value returned should be represented using the column name “id”.
ANS:
 SELECT id FROM user ORDER BY id DESC LIMIT 1,1
 
Q1: You wrote following script to check for the right category: 

$cate=5; 
... 
… 

if ($cate==5) 

?> 

Correct category! 
11 } 
else { 
?> 
Incorrect category! 
15 } 

?> 


What will be the output of the program if value of ‘cate’ remains 5? 
Correct category! 
Incorrect category! 
Error due to use of invalid operator in line 6:”if ($cate==5)” 
Error due to incorrect syntax at line 8, 10, 12 and 14 


Ans: Correct category!

Q2: What will be the result of following operation? 

128 
120 


Ans: 120

Q3: If expire parameter of setCookie function is not specified then: 
Cookie will never expire. 
Cookie will expire with closure of the browser 
Cookie will expire with within 30 minutes 
Cookie will expire in 24 hours 

Ans: Cookie will expire with closure of the browser
Q4: You need to count the number of parameters given in the URL by a POST operation. The correct way is: 
count($POST_VARS); 
count($POST_VARS_PARAM); 
count($_POST); 
count($HTTP_POST_PARAM); 

Ans: count($_POST);

Q5: Which of the following variables declarations within a class is invalid in PHP5? 
Private $type = ‘moderate’; 
Internal $term =3; 
Public $name =’500’; 
Protected $name = ‘Quantas Private Limited’; 

Ans: Protected $name = ‘Quantas Private Limited’;

Q6: Which of the following statements is not true with regard to abstract classes in PHP5? 
Abstract classes are introduced in PHP5 
A class with a single abstract method must be declared abstract 
Abstract class can contain non abstract methods 
Abstract method must have method definition and can have optional empty braces following it 

Ans: Abstract method must have method definition and can have optional empty braces following it

Q7: Which of the following pair have non-associative equal precedence? 
+,- 
==, != 
<<, >> 
&=, |= 

Ans: &=, |=empty braces following it

Q8: You have two strings, which you want to concatenate.


$str1 = ‘Have a ‘;

$str2 = ‘Nice Day’;


The fastest way would be: 
$str1. Concat($str2); 
$str1. $str2; 
“$str1$str2”; 
None of the above 

Ans: None of the above

Q9: For the following code: 
Function Expenses() 

Function Salary() 


Function Loan() 

Function Balance() 



?> 


Which of the following sequence will run successfully? 
Expenses();Salary();Loan();Balance(); 
Salary();Expenses();Loan();Balance(); 
Expenses();Salary();Balance();Loan(); 
Balance();Loan();Salary();Expenses(); 

Ans: Salary();Expenses();Loan();Balance();

Q10: Which of the following is not supported in PHP5? 
Type Hinting 
Reflection 
Magic Methods 
Multiple Inheritance 
Object Cloning 

Ans: Multiple Inheritance

Q11: How would you start a session? 
Session(start); 
Session(); 
Session_Start(); 
Begin_sesion(); 


Ans: Session_Start();


Q12: What do you infer from the following code?


$str=’Dear Customer,\nThanks for your query. We will reply very soon.?\n Regards.\n Customer Service Agent’: Print $str;


?> 
Only first\n Character will be recognized and new line will be inserted. 
Last \n Will not be recognized and only first two parts will come in new lines. 
All the \n Will work and text will be printed on respective new lines. 
All will be printed on one line irrespective of the \n. 


Ans: All the \n Will work and text will be printed on respective new lines. 


Q13: What will be the result of the following expression:


6+4*9-3 
60 
87 
39 
30 


Ans: 87


Q14: What is true regarding $a+$b where both of them are arrays? 
Duplicated keys are NOT overwritten 
87 
The + operator is overloaded 
This produces a syntax error 


Ans: $b is appended to $a


Q15: Which of the following characters are taken care of by html special chars? 


Single quote 
Double Quote 

All of the above 


Ans: >



Q16: The value of a local variable of a function has to be retained over multiple calls to that function. How should that variable be declared? 
Local 
Global 
Static 
None of the above 


Ans: Static



Q17: Which of the following multithreaded servers allow PHP as a plug-in? 
Netscape FastTrack 
Microsoft’s Internet Information Server 
O’Reilly’s WebSite Pro 
All of the above 


Ans: All of the above



Q18: Multiple select/load is possible with: 
Checkbox 
Select 
File 
All of the above 


Ans: All of the above






Q19: Which of the following variable names are invalid? 
$var_1 
$var1 
$var-1 
$var/1 
$v1 


Ans: $var1



Q20: Which of the following are useful for method overloading? 
_call,_get,_set 
_get,_set,_load 
_get,_set,_load 
_overload 


Answer is: _get,_set,_load






Q21: What will be the output of the following code?


Function fn(&$var)


{


$var=$var-($var/10*5);


Return $var;


}


Echo fn(100); 
100 
50 
98 
Error message 
None of the above 


Ans: None of the above


Q22: Which of the following type cast is not correct? 
$fig=23; 
$varb1 = (real) $fig; 
$varb2 = (double) $fig; 
$varb3 = (decimal) $fig; 
$varb4 = (bool) $fig; 
?> 
Real 
Double 
Decimal 
Boolean 


Ans: Double


Q23: What will be the output of following code?


$a = 10;


Echo “value of a = $a”; 
Value of a = 10 
Value of a = $a 
Undefined 
Syntax Error 


Ans: Value of a = $a


Q24: What will be the output of following code?


$var = 10;


Function fn()


{


$var = 20;


Return $var;


}


Fn();


Echo $var; 
10 
20 
Undefined Variable 
Syntax Error 


Ans: Syntax Error


Q25: Which of the following attribute is needed for file upload via form? 
Enctype=”multipart/form-data” 
Enctype=”singlepart/data” 
Enctype=”file” 
Enctype=” form-data/file” 


Ans: Enctype=”file”


Q26: Which of the following is not a file related function in PHP? 
Fclose 
Fopen 
Fwrite 
Fgets 
Fappend 


Ans: Fgets


Q27: Which of the following is correct with regard to echo and print? 
Echo is a construct and print is a function 
Echo is a function and print is a construct 
Both are functions 
Both are constructs 


Ans: Echo is a function and print is a construct


Q28: Which of the following is a correct declaration? 
Static $varb = array(1,’val’,3); 
Static $varb = 1+(2*90); 
Static $varb = sqrt(81); 
Static $varb = new object; 


Ans: Static $varb = new object;


Q29:


You are using sessions and session register() to register objects. These objects are serialized automatically at the end of each PHP page and are de-serialized automatically on each of the following pages. Is this true of false? 
True 
False 


Ans: True



Q30: Consider the following two statements:


I. While (expr) statement


II. While (expr): statement…endwhile;


Which of the following are true in context of the given statements? 
I is correct and II is wrong 
I is wrong and II is correct 
Both I & II are wrong 
Both I & II are correct 

Ans: I is wrong and II is correct


Best Wishes to all. Please subscribe to our Blog.

 
1. Question: What is true regarding this code?
Answer: setcookie will return true
2. Question: Which of the following is not a correct way of printing text in php5?
Answer: echo “Plain text”;
3. Question: Which of the following is not the correct way of starting a session?
Answer: session_initiate()
4. Question: Which of the following functions do you need to implement HTTP Basic Authentication?
Answer: None of the above
5. Question: Which of the following Command Line Interface constant is not defined in the CLI SAPI?
Answer: STDPRT
6. Question: Which of the following statements is correct with regard to final and abstract?
Answer: a. An abstract class cannot have final methods
7. Question: Which composite data types are supported by php?
Answer: Array
8. Question: The default value of register_globals in PHP is:
Answer: Off
9. Question: Which of the following is not a valid PHP connection status?
Answer: open
10. Question: Choose the correct statement:
Answer: include() includes and evaluates a specific file
require_once() includes and evaluates a specific file only if it has not been included before
11. Question: If the session_cache_expire() is not set, then by default the session cache will expire after:
Answer: 3 hrs
12. Question: What will be the output of the following script?
$count=50;
Paamayim Nekudotayim operator allows access only to the static members of a class?
Paamayim Nekudotayim operator allows access only to the static members of a class?
Answer: function_exists
$i=4;
User Name:
Password:
class Manager{
Answer: 5+2 * 4+6
$var = 1 + “-1.3e3″;
function Argument()
{
$count++;
echo $count;
}
Argument();
?>
Answer: It will print 1
13. Question: State whether True or False
Answer: True
14. Question: Which of the following statements is true with regard to comparisons in PHP5?
Answer: With (===) operator, object variables are identical if and only if they refer to the same instance of the same class.
15. Question: What will be the output of the following code?
$a = 0.0;
for ($i = 0; $i < a =”=”">
Answer: 1
16. Question: What will be the output of the following code?
$j=30;
$k=0;
$k=$j++/$i++;
echo $i . ” ” . $j . ” ” . $k . ” “;
Answer: 5 31 7.5
17. Question: Which of the following is a not a correct way of commenting in php?
Answer: /#PHP Comment
18. Question: Following is a php code block:
$m=9;
$n=99;
$z=8;
$z=$n++/$m++ + –$z;
echo $z;
what will be the output?
Answer: 18
19. Question: Which of the following is the correct way of specifying default value?
Answer: function GetDiscount($Type = “Special”) { . . . }
20. Question: With reference to the following php script:
print ‘Text Line1′
print ‘Text Line2′
?>
What will be the output on running the script?
Answer: Error message will be printed
21. Question: What will be the ouput of the following code?
for ($i = 0; $i < i =”=”">
0134
Question: Late PHP versions support remote file accessing for the functions:
Answer: include_once()
require_once()
both of them
22. Question: You have designed a user login form as follows:
How can you access the username entered by the user in the ‘Validate.php’ webpage?
a. $var= $_POST['username'];
b. $var= $_REQUEST['username'];
c. import_request_variables(‘p’, ‘p_’);
$var= $p_username;
Answer: Both of them
23. Question: Which of the following does not represent logical AND operator in PHP?
Answer: &amp
24. Question: Which of the following is not true for a persistent connection?
Answer: These can’t be converted to non-persistent connections
25. Question: Which of the following are invalid data types in PHP?
Answer: char
26. Question: The Manager and Office classes are as follows:
function printName() {
echo “Manager”;
}
}
class Office{
function getManager() {
return new Manager();
}
}
$ofc = new Office();
???
?>
Which of the following should replace ‘???’ to obtain the value of printName() function?
Answer: $ofc->getManager()->printName();
27. Question: The classes are defined as follows:abstract class BaseCls{
protected abstract function getName();
}
class ChildCls extends BaseCls{
}
Which of the following implementations of getName() is invalid in ChildCls?
Answer: public function getName(){}
28. Question: Which of the following variable declarations within a class is invalid in PHP5?
Answer: var $term =3;
29. Question: What will be the output of following code?
$arr = “a”;
$arr[0]=”b”;
echo $arr;
echo $arr[0];
Answer: bb
30. Question: For the following code:
the output will be:
Answer: 171
31. Question: What is the result of the following expression?
Question: What will be the output of following code?
echo $var;
Answer: -1299
32. Question: What will be the output of following code?
$var1=”a”;
$$var1=”b”;
echo “$var1 $a”;
Answer: a b
33. Question:What is the output of the following code?
$a = 500;
$b = 200;
echo $a % 2
* $b;
?>
Answer: 0
34. Question: What will be the ouput of the following code?
if (-1)
print “true”;
else
print “false”;
?>
Answer: true
35. Question: What will be the output of the following code?
echo 12 . 6;
Answer: 126
36. Question: Consider the following sample code:
$x = 0xFFFE;
$y = 2;
$z = $x && $y;
What will be the value of $z?
Answer: 1

Comments

Popular posts from this blog

Freelancer Wordpress Exam Answers 2016

100 percent Rank your website on Google for $13