السلام عليكم ورحمة الله وبركاته ...
نسخت بعض الاسئلة التي تأتي في الاختبار التجريبي لشركة Zend .. ونرغب من لديه معلومات ان يجيب على الاسئلة من باب الفائدة لنا ..
نرجوا من الاخوة الخبراء في PHP عامة و PHP5 .. عند الاجابة اخبارنا سبب اختياره .. لتعم الفائدة من هذه الفكرة ..
=======
Which of the following functions were added to PHP 5 for dealing with arrays?
array_intersect_key()
array_unshift()
array_diff_key()
array_merge()
array_slice()
==============
The _________ function is great for monitoring a series of streams to determine when one or more of them will not block a particular type of stream operation.
==============
Consider the following String:
كود PHP:
$string = "John\tMark\nTed\tLarry";
Which of the following functions would best parse the string above by the tab (\t) and newline (\n) characters?
كود PHP:
strsplit($string, "\t\n");
strtok($string, "\t\n");
strstr($string, "\t\n");
explode("\t\n", $string);
All of the above
================
Consider the following example XML document:
كود PHP:
<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>XML Example</title> </head> <body> <p> Moved to <<a href="http://example.org/">http://www.example.org/</a>.> <br> </p> </body></html>
What is wrong with this document, and how can it be corrected?
The document is completely valid
All special XML characters must be represented as entities within the content of a node
All tags must be closed
You cannot specify a namespace for the <html> attribute
The DOCTYPE declaration is malformed
=================
اختر 4 اجابات
Consider the following script:
كود PHP:
<?php
try {
$dbh = new PDO("sqlite::memory:");
} catch(PDOException $e) {
print $e->getMessage();
}
$dbh->query("CREATE TABLE foo(id INT)");
$stmt = $dbh->prepare("INSERT INTO foo VALUES(:value)");
$value = null;
$data = array(1,2,3,4,5);
$stmt->bindParam(":value", $value);
/* ?????? */
try {
foreach($data as $value) {
/* ????? */
}} catch(PDOException $e) {
/* ??????? */
}
/* ?????? */
?>
What lines of code need to go into the missing places above in order for this script to function properly and insert the data into the database safely?
كود PHP:
$dbh->beginTransaction();
$dbh->commit();
$stmt->execute();
$dbh->rollback();
$dbh->query($stmt);
=====================
To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.
array, interface
interface, implements
interface, extends
instance, implements
access-list, instance
====================
When is it acceptable to store sensitive information in an HTTP cookie?
Only under extremely controlled situations
When the cookie is sent over a secure HTTP request
When it is encrypted
It is always acceptable
=====================
Given the following array
كود PHP:
<?php
$a = array( 1 => 'red', 'green', 'blue', 'purple' => array( 'house' => 'dog', 'food' => 'meal', 'here' => 'gone', 'hello' => array( 5 => 'goodbye', 8 => 'something', 'correct')));
?>
Which of the following print statements will output the string "correct"?
print $a['purple][4][3];
print $a['purple']['hello'][9];
print $a[2][4][3];
print $a[2][4][9];
print $a[4]['hello'][9];
=========================
When an object is serialized, which method will be called, automatically, providing your object with an opportunity to close any resources or otherwise prepare to be serialized?
__destroy()
__serialize()
__destruct()
__shutdown()
__sleep()
=========================
What is the primary benefit of a SAX-based XML parser compared to DOM?
All of the above
Faster then DOM methods
Requires less memory then DOM
Easier to develop parsers
==========================
اختر 3 اجابات
The $_REQUEST super global contains what?
Data received from the session
Data received from Cookies
Data received from the server environment
Data received from HTTP POST
Data received from HTTP GET
=================
What is the output of the following code?
كود PHP:
<?php
function functionSplit(){
$pre = 1;
?>
<?php
echo $pre;
}
functionSplit();
?>
Error; function declarations can not be split over multiple PHP segments.
Nothing
1
2
===================
Unlike the old MySQL extension, the new MySQLi extension requires that you provide what when performing a query when using the procedural interface?
The query identifier
The database name
All function parameters
The database handle
The statement handle
==================
اختر 3 اجابات
What are the three access modifiers that you can use in PHP objects?
protected
public
static
private
final
============
Given the following XML document in a SimpleXML object:
كود PHP:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML Example</title>
</head>
<body>
<p>
Moved to <<a href="http://example.org/">http://www.example.org/</a>.>
<br/>
</p>
</body></html>
Select the proper statement below which will display the HREF attribute of the anchor tag.
$sxe->body->p[0]->a[1]['href']
$sxe->body->p->a->href
$sxe->body->p->a['href']
$sxe['body']['p'][0]['a']['href']
$sxe->body->p[1]->a['href']
===============
One can ensure that headers can always be sent from a PHP script by doing what?
Enable header buffering in PHP 5
Set the header.force INI directive to true
Enable output buffering in PHP 5
There is no way to ensure that headers can always be set, they must always be checked
None of the above
=============
What is the best way to ensure that a user-defined function is always passed an object as its single parameter?
function myfunction(stdClass $a)
function myfunciton($a = stdClass)
Use is_object() within the function
There is no way to ensure the parameter will be an object
function myfunction(Object $a)
=============
اختر 4 اجابات
Which of the following is incorrect?
function c(MyClass $a = new MyClass())
function d($a = null)
function e(&$a = 30)
function a(&$a = array(10,20,30))
function b($a = (10 + 2))
=============
اضف الكلمة
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 transaction.
=============
The ____________ function is used to modify the amount of time PHP will wait for a stream before timing out during reading or writing.
==============
Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct?
You cannot disable remote PHP script execution
curl.enabled
allow_remote_url
allow_url_fopen
allow_require
===============
When implementing a permissions system for your Web site, what should always be done with regards to the session?
None of the above
You should not implement permission systems using sessions
Sessions should be cleared of all data and re-populated
The session key should be regenerated
The session should be destroyed
==============
The _______ method will be called automatically when an object is represented as a string.
getString()
__get()
__value()
__toString()
__getString()
==============
Which statement will return the third parameter passed to a function?
$argv[3];
$argv[2];
func_get_args(3);
func_get_arg(2);
func_get_arg(3);
=============
اختر 3 اجابات
What would go in place of ?????? below to make this script execute without a fatal error?
كود PHP:
<?php
$a = 1;
$b = 0;
??????
$c = $a / $b;
?>
quit();
die();
stop();
__halt_compiler();
exit();
==========
The ____ construct is particularly useful to assign your own variable names to values within an array.
array_get_variables
current
each
import_variables
list
==========
Where should indirectly executed PHP scripts (i.e. include files) be stored in the file system?
Outside of the Document Root
In the document root
Anywhere you want
In the database
=============
اختر 2 اجابة
Why is it important from a security perspective to never display PHP error messages directly to the end user, yet always log them?
Error messages will contain sensitive session information
Error messages can contain cross site scripting attacks
Security risks involved in logging are handled by PHP
Error messages give the perception of insecurity to the user
Error messages can contain data useful to a potential attacker
==============
If you would like to store your session in the database, you would do which of the following?
-It requires a custom PHP extension to change the session handler
-Implement the session_set_save_handler() function
-Create functions for each session handling step and use session_set_save_handler() to override PHP's internal settings
-Configure the session.save_handler INI directive to your session class
=================
اختر 2 اجابة
What consistutes a View in the MVC pattern for PHP 5, in the following list?
Iterators
PDO
Classes
PHP
Smarty
============
Which PCRE regular expression will match the string PhP5-rocks?
كود PHP:
/^[hp1-5]*\-.*/i
كود PHP:
/[hp][1-5]*\-.*/
[PHP]/
كود PHP:
{3}[1-5]{2,3}\-.*$/
=============
What should be replaced in the string ??????? below to open the archive myarchive.gz located in the document root of the www.example.com server and decompress it?
كود PHP:
<?php
$file = '???????';
$fr = fopen($file, 'rb');
$data = "";
while(!feof($fr))
{
$data .= fgets($fr, 1024);
}
fclose($fr);
?>
compress.zlib://{$http}www.example.com/myarchive.gz
compress.zlib://http://www.example.com/myarchive.gz
compress.http://www.example.com/myarchive.gz
compress.http.zlib://www.example.com/myarchive.gz
compress.zlib://myarchive.gz
=============
Setting a HTTP cookie on the client which is not URL-encoded is done how in PHP 5?
Use the setrawcookie() function
Set the cookies.urlencode INI directive to false
Use urldecode() on the return value of setcookie()
Setting the $no_encode parameter of setcookie() to a boolean 'true'
All cookies must be URL encoded
===============
اختر 3 اجابات
Which of the following operations must occur prior to any output being sent to the client (assume output buffering is disabled).
Modifying Session Data
Processing GET or POST data
Manipulating Cookie data
Starting a Session
Sending HTTP Headers
============
اختر 2 اجابة
What kind of information is acquired when profiling a PHP script?
A list of all of the op-codes executed by the engine
The files and functions and/or parameters which were executed during the PHP script
The execution times of files and functions during the PHP script
A list of all the variables used in a PHP script
A list of errors which have occurred
============
Event-based XML parsing is an example of which parsing model?
SAX
DOM
XML Object Mapping
XPath
XQuery
============
What is the output of the following code?
كود PHP:
<?php
class MyException extends Exception {
}
class AnotherException extends MyException {
}
class Foo {
public function something() {
throw new AnotherException();
}
public function somethingElse() {
throw new MyException();
}
}
$a = new Foo();
try {
try {
$a->something();
}
catch(AnotherException $e) {
$a->somethingElse();
}
catch(MyException $e) {
print "Caught Exception";
}
} catch(Exception $e) {
print "Didn't catch the Exception!";
}
?>
"Caught Exception" followed by "Didn't catch the Exception!"
A fatal error for an uncaught exception
"Didn't catch the Exception!"
"Didn't catch the Exception!" followed by a fatal error
"Caught Exception"
===============
اختر 3 اجابات
SimpleXML objects can be created from what types of data sources?
A String
An array
A DomDocument object
A URI
A Database resource
===========
What is the output of this code snippet?
كود PHP:
<?php
$a = array(0.001 => 'b', .1 => 'c');
print_r($a);
?>
An empty array
0.001 => 'b', .1 => c
0 => 'c'
'0.001' => 'b', '0.1' => c'
A Syntax Error
=============
How can you modify the copy of an object during a clone operation?
Put the logic in the object's constructor to alter the values
Implment your own function to do object copying
Implement the object's __clone() method
Implement __get() and __set() methods with the correct logic
Implement the __copy() method with the correct logic
================
How could the following PHP 4 code snippet be re-written in PHP 5?
كود PHP:
<?php
$arr = array('foo' => 5, 2 => 'hi', 6 => 8);
foreach($arr as $key => $value) {
if($key == 2) {
$arr[$key] = 10;
}
}
?>
$arr[$key] is no longer necessary, use $arr instead to modify a value
You cannot change array value types during interation in PHP 5
$value can be prepended with &, and modified directly
In PHP 5 you cannot modify an array during iteration using foreach()
None of the above
================
Consider the following code segment:
كود PHP:
<?php.
$xmldata = <<< XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML Example</title>
</head>
<body>
<p>
Moved to <<a href="http://example.org/">http://www.example.org/</a>.>
<br/>
</p>
</body></html>XML;
$xml = xml_parser_create("UTF-8");
/* ??????? */
xml_parse($xml, $xmldata);
function xml_start_handler($xml, $tag, $attributes) {
print "Tag: $tag<br/>\n";
}
function xml_end_handler($xml, $tag)
{
}
?>
What should be placed in place of ?????? above to have the above script display the name of each tag within the XML document?
xml_set_callback("xml_start_handler");
xml_set_element_handler($xml, "xml_start_handler", "xml_end_handler");
xml_node_set_handler("xml_start_handler", "xml_end_handler");
xml_node_set_handler("xml_start_handler");
===============
When connecting to a database using PDO, what must be done to ensure that database credentials are not compromised if the connection were to fail?
wrap the PDO DSN in a try/catch block to catch any connection exception
Use constants in the PDO DSN
Place the login credentials in the php.ini file
Disable E_STRICT and E_NOTICE error reporting levels
==============
هذا والله الموفق ...