PHP Theoritical Mocks Without Answer
PHP Theoritical Mocks Without Answer
PHP Theoritical Mocks Without Answer
3. Which of the following statements is NOT true? A. It is possible to specify more than one __autoload
function
a) Class constants are public B. __autoload receives the missing class name all
b) Class constants are being inherited lowercased
c) Class constants can omit initialization (default to NULL) C. __autoload is being called for missing interfaces
d) Class constants can be initialized by consts D. Inside __autoload missing classes trigger __autoload
4. When a class is defined as final it: 10. Which of the following is correct? (Choose 2)
A. Can no longer be extended by other classes. A. A class can extend more than one class.
B. Means methods in the class are not over-loadable. B. A class can implement more than one class.
C. Cannot be defined as such, final is only applicable to C. A class can extend more than one interface.
object methods. D. A class can implement more than one interface.
D. Is no longer iteratable. E. An interface can extend more than one interface.
F. An interface can implement more than one
interface.
14. PHP's array functions such as array_values() and 20. How can you modify the copy of an object during a
array_key_exists() can be used on an object if the clone operation?
object...
A. Put the logic in the object's constructor to alter the
A. implements Traversable
B. is an instance of ArrayObject values
C. implements ArrayAccess B. Implment your own function to do object copying
D. None of the above C. Implement the object's __clone() method
D. Implement __get() and __set() methods with the
correct logic
E. Implement the __copy() method with the correct
15. What is the name of the method that can be used to logic
provide read access to virtual properties in a class?
A. __call()
B. __get() 21. What is the primary difference between a method
C. __set() declared as static and a normal method?
D. __wakeup()
E. __fetch() A. Static methods can only be called using the ::
syntax and never from an instance
B. Static methods do not provide a reference to $this
C. Static methods cannot be called from within class
16. Which of the following function signatures is instances
correct if you want to have classes automatically
D. Static methods don't have access to the self
loaded?
keyword
A. function autoload($class_name) E. There is no functional difference between a static
B. function __autoload($class_name, $file) and non-static method
C. function __autoload($class_name)
D. function _autoload($class_name)
E. function autoload($class_name, $file)
22. The ______ keyword is used to indicate an
incomplete class or method, which must be further
extended and/or implemented in order to be used.
24. Type-hinting and the instanceof keyword can 30. Creating new nodes in XML documents using
be used to check what types of things about PHP can be done using which XML/PHP 5
variables? Choose 3 technologies?
A. XQuery
A. If a particular child class extends from it B. XPath
B. If they are an instance of a particular interface C. SimpleXML
C. If they are an abstract class D. DOM
D. If they have a particular parent class E. SAX
E. If they are an instance of a particular class
25. PHP 5 supports which of the following XML 31. When working with SimpleXML in PHP 5, the
parsing methods? four basic rules on how the XML document is
A. SAX accessed are which of the following?
B. FastDOM A. Element namespaces are denoted by the
C. DOM 'namespace' attribute
D. XPath B. converting an element to a string denotes text
E. XML to Object mapping data
C. Non-numeric indexes are element attributes
D. Numeric indexes are elements
E. Properties denote element iterators
A. SimpleXML allows removal of attributes. 42. Which of the following XML declarations is
B. SimpleXML allows addition of new attributes. NOT valid?
C. SimpleXML allows removal of nodes.
D. SimpleXML allows addition of new nodes. A. <?xml version="1.0" ?>
E.None of the above B. <?xml version="1.1" encoding="UTF-8" ?>
C. <?xml standalone="no" ?>
D. <?xml standalone="1" ?>
A. XML-RPC
B. SOAP
38. Which of the following are valid SoapClient C. WSDL
calls? (Choose 2) D. UDDI
59. If you would like to store your session in the 64. Setting a HTTP cookie on the client which is not
database, you would do which of the following? URL-encoded is done how in PHP 5?
A. It requires a custom PHP extension to change the A. Use the setrawcookie() function
session handler B. Set the cookies.urlencode INI directive to false
B. Implement the session_set_save_handler() C. Use urldecode() on the return value of setcookie()
function D. Setting the $no_encode parameter of setcookie()
C. Create functions for each session handling step to a boolean 'true'
and use session_set_save_handler() to override E. All cookies must be URL encoded
PHP's internal settings
D. Configure the session.save_handler INI directive to
your session class
65. During an HTTP authentication, how does one
determine the username and password provided by
the browser?
60. To destroy a PHP session completely, one must A. Parse the HTTP headers manually using
which of the following? http_get_headers()
A. Regenerate the session ID using B. Use the get_http_username() and
session_regenerate_id() get_http_password() functions
B. If cookies are used, destroy it C. Use the $_SERVER['HTTP_USER'] and
C. Use session_demolish() to completely destroy the $_SERVER['HTTP_PASSWORD'] variables
session D. Use the $_SERVER['PHP_AUTH_USER'] and
D. Change the session name using session_name() $_SERVER['PHP_AUTH_PW'] variables
E. Destroy the session data using session_destroy() E. Parse the $_SERVER['REQUEST_URI'] variable
61. If you would like to change the session ID 66. onsider the following function:
generation function, which of the following is the
best approach for PHP 5? <?php
A. Set the session.hash_function INI configuration function redirect($url) {
directive // Check to make sure we haven't
B. Use the session_set_id_generator() function already sent
C. Set the session id by force using the session_id() // the header:
function
if(???????) {
D. Use the session_regenerate_id() function header("Location: $url");
E. Implement a custom session handler }
}
?>
62. Setting a cookie on the client in PHP 5 can be best
accomplished by: What conditional should replace the ????? above?
A. Use the add_cookie() function
B. Use the setcookie() function
A. !in_array("Location: $url", headers_list())
C. Use the the apache_send_header() function
B. !header_exists("Location: $url")
D. Setting a variable in the $_COOKIE superglobal
C. !header_location($url)
D. $_SERVER['HTTP_LOCATION'] != $url
63. How does one create a cookie which will exist only
until the browser session is terminated?
A. You cannot create cookies that expire when the 67. One can ensure that headers can always be sent
from a PHP script by doing what?
browser session is terminated
A. Enable header buffering in PHP 5
B. Set the header.force INI directive to true
C. Enable output buffering in PHP 5
D. There is no way to ensure that headers can always 73. Which of the following functions allow you to
be set, they must always be checked introspect the call stack during execution of a PHP
E. None of the above script?
A. get_backtrace()
B. get_function_stack()
C. debug_backtrace()
68. When is it acceptable to store sensitive information D. debug_print_backtrace()
in an HTTP cookie? E. print_backtrace()
A. Only under extremely controlled situations
B. When the cookie is sent over a secure HTTP
request
C. When it is encrypted 74. When running PHP in a shared host environment,
D. It is always acceptable what is the major security concern when it comes
to session data?
A. Sessions on shared hosts are easily hijacked by
outside malicious users
69. When using a function such as strip_tags, are B. All of the above
markup-based attacks still possible? C. You cannot use a custom data store in shared
A. No, HTML does not pose any security risks hosts
B. Yes, even a <p> HTML tag is a security risk D. Session data stored in the file system can be read
C. Yes, attributes of allowed tags are ignored by other scripts on the same shared host
D. No, strip_tags will prevent any markup-based E. Users outside the shared host can access any site
attack which created a session for them
70. Where should indirectly executed PHP scripts (i.e. 75. Which of the following filtering techniques
include files) be stored in the file system? prevents cross-site scripting (XSS)
A. Outside of the Document Root vulnerabilities?
B. In the document root
C. Anywhere you want A. Strip all occurrences of the string script.
D. In the database B. Strip all occurrences of the string javascript.
C. Enable magic_quotes_gpc.
D. None of the above.
A. TRUE
B. FALSE
C. ENT_QUOTES 86. In a shared hosting environment, session data
D. ENT_NOQUOTES can be read by PHP scripts written by any user.
E. ENT_COMPAT How can you prevent this?
A. Check with is_uploaded_file() whether the uploaded file 97. You need to escape special characters to use
$_FILES['myFile']['tmp_name'] is valid user input inside a regular expression. Which
B. Sanitize the file name in $_FILES['myFile']['name'] functions would you use? (Choose 2)
because this value is not consistent among web browsers
C. Check the charset encoding of the HTTP request to see A. addslashes()
whether it matches the encoding of the uploaded file B. htmlentities()
D. Sanitize the file name in $_FILES['myFile']['name'] C. preg_quote()
because this value could be forged D. regex_quote()
E. Use $HTTP_POST_FILES instead of $_FILES to maintain E. quotemeta()
upwards compatibility
114. How can one take advantage of the time waiting for
a lock during a stream access, to do other tasks
109. Which of the following is not a valid default stream using the following locking code as the base:
wrapper for PHP 5, assuming OpenSSL is enabled?
A. ftps:// $retval = flock($fr, LOCK_EX);
B. ftp://
C. sftp:// A. Use flock_lazy() instead of flock()
D. https:// B. Use LOCK_EX|LOCK_NB instead of LOCK_EX
E. http:// C. Use LOCK_UN instead of LOCK_EX
D. Check the value of $retval to see if the lock was
obtained
E. Check to see if $retval == LOCK_WAIT
110. When opening a file in writing mode using the FTP
handler, what must be done so that the file will still
be written to the server in the event it previously
exists?
115. Which of the following extensions are no longer
A. Provide a context for fopen() using part of PHP 5 and have been moved to PECL?
stream_context_create() A. tidy
B. You must delete the file first before uploading a B. mysql
new file C. w32api
C. Configure this behavior in the php.ini file using the D. curl
ftp.overwrite directive E. dio
D. Open the file using the 'w+' mode
119. When connecting to a database using PDO, what A. The filename of the current script.
must be done to ensure that database credentials are B. The full path to the current script.
not compromised if the connection were to fail? C. The URL of the request made.
A. wrap the PDO DSN in a try/catch block to catch D. The path to the main script.
any connection exception
B. Use constants in the PDO DSN
C. Place the login credentials in the php.ini file
D. Disable E_STRICT and E_NOTICE error reporting 126. What PHP function can be used to remove a
levels local file?
A. rmdir()
B. unlink()
C. rm()
120. Implementing your own PDO class requires which
D. delete()
steps from the list below?
E. delete_file()
A. Extending the PDOStatement Class
B. Set the PDO::ATTR_STATEMENT_CLASS parameter
C. Call the PDO::setStatementClass() method
D. Extend the PDO class
E. Set the PDO::ATTR_USE_CLASS parameter
127. What function returns the filename component of
the file's path:
A.dirname()
B.realpath()
121. What function is used to retrieve all available C. basename()
information about a symbolic link? D. pathinfo()
E. parse_url()
A. symlink()
B. stat()
C. fstat()
D. lstat()
E. readlink() 128. After executing a query on a database server,
PHP offers several functions to read the
resulting lines, such as mysqli_fetch_assoc,
pg_fetch_row, oci_fetchtc.). If such functions do
not return any rows, it means: (Choose 2)
122. After executing a SELECT query on a database
server, A. a SELECT statement returned no rows
B. the transaction has been rolled back
A. All data is immediately transmitted to PHP C. the connection to the database server was disconnected
B. All data will be transmitted on-demand to PHP during query execution
C. None of the above D. the query was too slow to execute
123. Transactions are used to: 129. An unbuffered query will: (Choose 2)
A. guarantee high performance
B. secure data consistency A. Return the first data faster
C. secure access to the database B. Return all data faster
D. reduce the database server overhead C. Free connection faster for others scripts to use
E. reduce code size in PHP D. Use less memory
124. Some databases support the LIMIT clause. It is 130. Which of the following commands will append
a method to ensure that ... data to an existing file?
A. only certain rows are deleted in DELETE queries. A. file_put_contents("file", "data", "a");
B. only a defined subset of rows are read in SELECT B. file_put_contents("file", "a", "data");
queries. C. file_put_contents("file", "data", FILE_APPEND);
C. only certain users can access the database. D. file_put_contents("file", "a", NULL, FILE_APPEND);
136. Which of the following actions must be taken
before this code may go into production? (Choose
2)
131. Which elements does the array returned by the
function pathinfo() contain? A. Check with is_uploaded_file() whether the uploaded file
$_FILES['myFile']['tmp_name'] is valid
A. root, dir, file B. Sanitize the file name in $_FILES['myFile']['name']
B. dirname, filename, fileextension because this value is not consistent among web browsers
C. dirname, basename, extensio C. Check the charset encoding of the HTTP request to see
D. path, file whether it matches the encoding of the uploaded file
D. Sanitize the file name in $_FILES['myFile']['name']
because this value could be forged
E. Use $HTTP_POST_FILES instead of $_FILES to maintain
upwards compatibility
132. Which requirements need NOT be met so that
file uploads work?
A. The PHP directive file_uploads must be set to On 137. When a transaction reports no affected rows, it
B. The form's method attribute must be set to "post" means that: (Choose 2)
C. Safe mode must be turned off so that the uploaded file an
be written to the server A. The transaction failed
D. The form's enctype attribute must be set to B. The transaction affected no lines
"multipart/form-data" C. The transaction was rolled back
D. The transaction was committed without error
133. How can precisely one byte be read from a file, 138. What does the chown() function do?
pointed by $fp? (Choose 2)
A. Change the file permissions.
A. fread($fp, 1); B. Change the owner of the file.
B. fgets($fp, 1); C. Change the group of the file.
C. fgetss($fp, 1); D. Checks if the file is accessible.
D. fgetc($fp);
E. All of the above
A. file_get_contents()
B. readfile() 148. Which of the following statements is true?
C. fread()
D. include() A. All PHP database extensions support prepared statements
E. require() B. All PHP database extensions come with their own special
F. file() helper functions to escape user data to be used in dynamic
SQL queries
C. All PHP database extensions provide an OOP interface
D. All PHP database extensions appear in the output of php
143. Which of the following will set a 10 seconds read -m , if installed
timeout for a stream?
A. ini_set("default_socket_timeout", 10);
B. stream_read_timeout($stream, 10); 149. Which of the following statements about
C. Specify the timeout as the 5th parameter to the database connections are commonly true?
fsockopen() function used to open a stream (Choose 2)
D. stream_set_timeout($stream, 10);
E. None of the above A. Database connections are closed after each SQL
statement is executed
B. Database connections are closed at the end of each
request
144. What is the ideal method of copying data C. Database connections are only closed when the Web
between two opened files? server shuts down
D. A single database connection may serve more than one
A. copy($source_file, $destination_file); PHP application at the same time
B. copy(destination_file, $source_file);
C. stream_copy_to_stream($source_file, $destination_file);
D. stream_copy_to_stream($destination_file, $source_file);
E. stream_bucket_prepend($source_file, $destination_file); 150. Which of the following code snippets writes the
content of the file "source.txt" to
"target.txt"?(Choose 3)
A. SQLite Database
B. MySQL Database
C. Shared Memory