NOTE : The answers That I am NOT sure are marked with "*"
Useful website: http://zend-php.appspot.com/
1. What is the best way to ensure the distinction between filtered / trusted and unfiltered / untrusted data?
A. None of the above
B. Never trust any data from the user
C. Enable built-in security features such as magic_quotes_gpc and safe_mode
D. Always filter all incoming data
E. Use PHP 5's tainted mode
Answer: D
2. In PHP5 you can use the ____ operator to ensure that can object is of a particular type. You can also use ____ in the function declaration.
A. instanceof, is_a
B. instanceof, type-hinting
C. type, instanceof
D. ===, type-hinting
E. ===, is_a
Answer: B (Here it refer to "function declaration", so use "type-hinting")
3. What is the difference between the include and require language constructs?
A. Require constructs can't be used with URL filenames.
B. Include constructs cause a fatal error if the file doesn't exist
C. There is no difference other than the name
D. Include constructs are processed at run time; require constructs are processed at compile time
E. Require constructs cause a fatal error if the file can't be read
Answer: E
4. What is the best way to iterate and modify every element of an array using PHP 5?
A. You cannot modify an array during iteration
B. for($i = 0; $i < count($array); $i++) { /* ... */ }
C. foreach($array as $key => &$val) { /* ... */ }
D. foreach($array as $key => $val) { /* ... */ }
E. while(list($key, $val) = each($array)) { /* ... */
Answer: C
5. What is wrong with the following code?
function duplicate($obj){
$newObj = $obj;
return $newObj;
}
$a = new MyClass();
$a_copy = duplicate($a);
$a->setValue(10);
$a_copy->setValue(20);
?>
A. You must use return &$newObj instead
B. There is nothing wrong with this code
C. duplicate() must accept its parameter by reference
D. You must use the clone operator to make a copy of an object
E. duplicate() must return a reference
Answer: D
6. In an application which will be under high load, SQLite could be useful for what sort of tasks?
A. As your primary database
B. SQL shouldn't be used in a high load environment
C. SQLite should only be used for in-memory databases in this environment
D. Session Management
E. Read-only databases
Answer: C
7. What is the output of the following PHP code?
define('FOO', 10);
$array = array(
10=>FOO,
"FOO"=>20
);
print $array[$array[FOO]] * $array["FOO"];
?>
A. FOO
B. 100
C. 200
D. 20
E. 10
Answer: C
8. when executing system commands from PHP, what should one do to keep applications secure? (choose 3)
A. Remove all quote characters from variables used in a shell execution
B. Avoid using shell commands when PHP equivlents are available
C. Hard code all shell commands
D. Escape all shell arguments
E. Escape all shell commands executed
Answer: BCD
9. Which of the following functions were added to PHP 5 for dealing with arrays? (choose 2)
A. array_intersect_key()
B. array_unshift()
C. array_diff_key()
D. array_merge()
E. array_slice()
Answer: AC
10. When working with a database, which of the following can be used to mitigate the possibility of exposing your database credientials to a malicious user? (choose 3)
A. Moving all database credentials into a single file
B. Moving all database credentials outside of the document root
C. Restricting access to files not designed to be executed independently
D. Setting creditial information as system environment variables
E. Using PHP constants instead of variables to store credentials
Answer: BCD
11. Which function is best suited for removing markup tags from a string?
A. strip_markup
B. strip_tags
C. str_replace
D. preg_replace
E. preg_strip
Answer: B
12. Which of the following comparisons will evaluate to true? (choose 3)
A. 't' == t
B. 1 === '1time'
C. "top" == 0
D. "top" === 0
E. 1 == "1time"
Answer: CE (I'm not sure whether to choose A or not, but B and D are wrong)
13. The ____ context variable allows you to define a callback for the stream that will notify your script of certain events during the course of the transation.
Answer: $params['notification']
14. The ____keyword is used to indicate an incomplete class or method, which must be further extended and / or implement in order to be used.
A. final
B. protected
C. incomplete
D. abstract
E. implements
Answer: D
15. The ____ function is used to add up the values of every entry within an array
Answer: array_sum
16. When implementing a permissions system for you web site, what should always be done with regards to the session?
A. none of the above
B. you should not implement permission systems using sessions
C. session should be cleared of all data and re-populated
D. the session key should be regenerated
E. the session should be destroyed
Answer: D
17. What is the best way to ensure the distinction between filtered / trusted and unfiltered / untrusted data?
A. None of the above
B. Never trust any data from the user
C. Enable built-in security features such as magic_quotes_gpc and safe_mode
D. Always filter all incoming data
E. Use PHP 5's tainted mode
Answer: D
18. In PHP 5 you can use the ____ operator to ensure that an object is of a particular type. You can also use ____ in the function declaration.
A. instanceof, is_a
B. instanceof, type-hinting
C. type, instanceof
D. ===, type-hinting
E. ===, is_a
Answer: B
19. What is the output of this code snippet?
'b', '0.1'=>c'));?>
A. An empty array
B. 0.001=>'b', .1=>c
C. 0=>'c'
D. '0.001'=>'b', '0.1'=>c'
E. A Syntax Error
Answer: C
20. Using flock() to lock a stream is only assured to work under what circumstances?
A. When running in a Linux environment local filesystem
B. When accessing the stream of the local filesystem
C. When running in a Windows environment and accessing a share
D. When accessing a bi-directional stream
E. When accessing a read-only stream
Answer: A
21. Given the following array:
$array = array(
1, 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 3, 2, 2, 2
);
The fastest way to determine the total number a particular value appears in the array is to use which function?
A. array_total_values
B. array_count_values
C. A foreach loop
D. count
E. a for loop
Answer: B
22. Given the following XML document in a SimpleXML object: