Docsity

Zend PHP 5 Practice Exam, Exams of Technology

Toggle sidebar
bg1
Zend PHP 5 Practice Exam
Question 1. Which of the following is the correct way to start and end a PHP block in a script?
A) <?php ... ?>
B) <php> ... </php>
C) <script> ... </script>
D) <? ... ?>
Answer: A
Explanation: PHP scripts are enclosed within <?php at the start and ?> at the end, making option A
correct.
Question 2. What is the result of the following code? $x = "5"; $y = 10; echo $x + $y;
A) 510
B) 15
C) 5
D) "510"
Answer: B
Explanation: PHP automatically converts $x to an integer, so "5" + 10 results in 15.
Question 3. Which variable scope allows a variable to be accessed anywhere in a PHP script?
A) Local
B) Global
C) Static
D) Function
Answer: B
Explanation: Global variables can be accessed from any part of the script using the global keyword or
$GLOBALS array.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51

Partial preview of the text

Download Zend PHP 5 Practice Exam and more Exams Technology in PDF only on Docsity!

Question 1. Which of the following is the correct way to start and end a PHP block in a script? A) <?php ... ?> B) <php> ... </php> C) <script> ... </script> D) <? ... ?> Answer: A Explanation: PHP scripts are enclosed within <?php at the start and ?> at the end, making option A correct. Question 2. What is the result of the following code? $x = "5"; $y = 10; echo $x + $y; A) 510 B) 15 C) 5 D) "510" Answer: B Explanation: PHP automatically converts $x to an integer, so "5" + 10 results in 15. Question 3. Which variable scope allows a variable to be accessed anywhere in a PHP script? A) Local B) Global C) Static D) Function Answer: B Explanation: Global variables can be accessed from any part of the script using the global keyword or $GLOBALS array.

Question 4. What is the output of the following? $foo = NULL; echo gettype($foo); A) boolean B) NULL C) string D) integer Answer: B Explanation: gettype() returns 'NULL' when the variable is set to NULL. Question 5. Which of the following is a valid way to define a constant 'PI' with value 3.14? A) define('PI', 3.14); B) constant('PI', 3.14); C) $PI = 3.14; D) const PI = 3.14; Answer: A Explanation: The define() function is used to declare constants in global scope. Question 6. Which superglobal contains information about headers, paths, and script locations? A) $_GET B) $_POST C) $_SERVER D) $_SESSION Answer: C Explanation: $_SERVER contains information about the server environment. Question 7. What will be the output of echo 5 == "5";?

B) 4

C) 12

D) 8

Answer: A Explanation: 6 divided by 2 equals 3. Question 11. Which PHP function returns the number of elements in an array? A) count() B) size() C) length() D) elements() Answer: A Explanation: count() returns the number of elements in an array. Question 12. Which is the correct way to begin a single-line comment in PHP? A) // comment B) <!-- comment --> C) ## comment D) * comment Answer: A Explanation: // begins a single-line comment in PHP. Question 13. What does the $_POST superglobal contain? A) Data sent via HTTP GET B) Data sent via HTTP POST

C) Cookie data D) Server variables Answer: B Explanation: $_POST contains data sent by HTTP POST method. Question 14. Which operator is used for concatenating two strings in PHP? A) + B). C) & D) * Answer: B Explanation: The dot (.) operator is used to concatenate strings. Question 15. What is the output of var_dump(5.5);? A) int(5.5) B) float(5.5) C) string(5.5) D) double(5.5) Answer: B Explanation: var_dump() shows the type and value; float(5.5). Question 16. Which keyword is used to access a global variable inside a function? A) global B) $GLOBALS C) extern

Answer: A Explanation: The const keyword is used for class constants. Question 20. Which magic constant returns the current line number of the file? A) LINE B) FILE C) FUNCTION D) CLASS Answer: A Explanation: LINE returns the current line number in the file. Question 21. What is the output of the following? $x = 5; $y = &$x; $y = 10; echo $x; A) 5 B) 10 C) 0 D) Error Answer: B Explanation: $y is a reference to $x; changing $y changes $x too. Question 22. Which function can be used to convert a string to an integer? A) intval() B) strval() C) floattype() D) to_int() Answer: A

Explanation: intval() converts a variable to an integer. Question 23. Which of the following is NOT a valid PHP variable name? A) $foo B) $_foo C) $2foo D) $foo Answer: C Explanation: Variable names cannot start with a digit. Question 24. What is the result of the following code? $num = 5; $num += 2; echo $num; A) 5 B) 2 C) 7 D) 10 Answer: C Explanation: The += operator adds 2 to $num, making it 7. Question 25. What does the === operator do in PHP? A) Compares values only B) Compares values and types C) Assigns values D) Concatenates values Answer: B Explanation: The triple equals (===) operator compares both value and type.

Question 29. Which function includes and evaluates a specified file during execution, and produces a fatal error if the file is not found? A) require() B) include() C) include_once() D) require_once() Answer: A Explanation: require() causes a fatal error if the file cannot be included. Question 30. What is the default scope of variables declared inside a function? A) Global B) Static C) Local D) Public Answer: C Explanation: Variables declared inside functions are local by default. Question 31. Which of the following is used to suppress errors in PHP? A) @ B) # C)! D) % Answer: A Explanation: The @ operator suppresses error messages.

Question 32. What does the function empty() return if the variable is set to 0? A) true B) false C) 0 D) null Answer: A Explanation: empty() returns true for values considered empty, including 0. Question 33. Which function is used to start a session in PHP? A) session_start() B) start_session() C) begin_session() D) session_begin() Answer: A Explanation: session_start() initializes a new session or resumes an existing one. Question 34. How do you check if a file exists before opening it? A) file_exists() B) is_file() C) exist_file() D) check_file() Answer: A Explanation: file_exists() checks if a file or directory exists. Question 35. Which function is used to redirect a user to another page?

B) 3

C) 4

D) 1

Answer: B Explanation: "PHP" has three characters. Question 39. Which PHP function is used to remove whitespace from the beginning and end of a string? A) trim() B) strip() C) remove() D) cut() Answer: A Explanation: trim() removes whitespace from both ends of a string. Question 40. How do you access the value 'bar' in the array $arr = array('foo' => 'bar');? A) $arr['foo'] B) $arr[0] C) $arr->foo D) $arr['bar'] Answer: A Explanation: Associative arrays use the key in square brackets. Question 41. Which of the following statements creates an indexed array? A) $arr = array(1, 2, 3); B) $arr = array('a' => 1, 'b' => 2);

C) $arr = array(1 => 'a', 2 => 'b'); D) $arr = array(); Answer: A Explanation: array(1, 2, 3) creates an indexed array. Question 42. What will be the output? echo 'Hello $name'; A) Hello B) Hello $name C) Hello (name) D) Hello "" Answer: B Explanation: Single quotes do not interpolate variables. Question 43. Which function converts an array to a string? A) implode() B) explode() C) join() D) merge() Answer: A Explanation: implode() joins array elements into a string. Question 44. Which of the following is used to declare a multi-dimensional array? A) $arr = array(array(1,2), array(3,4)); B) $arr = array(1,2,3,4); C) $arr = array('a' => 1, 'b' => 2);

Answer: A Explanation: static variables retain their value between function calls. Question 48. What will the following output? $x = 10; $y = ($x > 5)? 'yes' : 'no'; echo $y; A) yes B) no C) 10 D) Error Answer: A Explanation: 10 > 5 is true, so 'yes' is assigned to $y. Question 49. How do you access the value of a submitted form field named 'username' using the GET method? A) $_GET['username'] B) $_POST['username'] C) $_FORM['username'] D) $_REQUEST['username'] Answer: A Explanation: $_GET is used for data sent via GET. Question 50. Which function is used to split a string into an array? A) explode() B) implode() C) split() D) separate()

Answer: A Explanation: explode() splits a string by a delimiter. Question 51. Which of the following is NOT a valid data type in PHP? A) float B) character C) boolean D) string Answer: B Explanation: PHP does not have a 'character' data type. Question 52. Which function is used to check if a value exists in an array? A) in_array() B) array_key_exists() C) array_search() D) isset() Answer: A Explanation: in_array() checks for the presence of a value in an array. Question 53. Which function is used to delete a file in PHP? A) unlink() B) delete() C) remove() D) erase() Answer: A

Question 57. How do you access a class constant named VERSION from within the class? A) self::VERSION B) $this->VERSION C) $VERSION D) class::VERSION Answer: A Explanation: self:: is used to access class constants and static properties from within the class. Question 58. Which visibility keyword allows class members to be accessed from anywhere? A) public B) protected C) private D) static Answer: A Explanation: public members are accessible from anywhere. Question 59. What is the parent class of all exception classes in PHP 5? A) Exception B) BaseException C) Throwable D) Error Answer: A Explanation: Exception is the base class for all exceptions in PHP 5.

Question 60. Which function is used to register an autoload function in PHP 5? A) spl_autoload_register() B) register_autoload() C) autoload_register() D) load_class() Answer: A Explanation: spl_autoload_register() is the standard way to register autoload functions. Question 61. Which keyword is used to inherit from a parent class? A) extends B) inherits C) parent D) implements Answer: A Explanation: The extends keyword is used for inheritance. Question 62. Which PHP OOP feature restricts access to certain class properties or methods? A) Encapsulation B) Polymorphism C) Inheritance D) Abstraction Answer: A Explanation: Encapsulation is achieved using access modifiers. Question 63. Which keyword is used to implement an interface in a class?