Zend PHP5 certification Exam study review 12: supplementary III
Ok, this is the last part of my reviews. This post listed some WEIRD and STRANGE questions I found in the phparch’s simulator exam. You may think these are some advanced features of the PHP5 language, but some of them are actually mention in the GUIDE also. However, some of the questions, I found that there maybe some errors in the question itself; in this case, I marked with the “*” in front of the question. Therefore, some of the answer I gave maybe not right, or maybe I get the meaning of the questions wrong. So, if you have any comment on this post, please feel free to comment or send me a message. Thanks!
What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found?
__get($name)
__set($set, $val)
__call($method, $args)
__get() and __set() are called when accessing or assigning an undefined object property, while __call() is executed when calling a non-existent method of a class.
* When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for?
Force column names to a specific case specified by the PDO::CASE_* constants.
*XPath
<?php
$dom = new DomDocument();
$dom->load(’test.xml’);
$xpath = new DomXPath($dom);
DOMXPath->query() — Evaluates the given XPath expression
$nodes = $xpath->query(???????, $dom->documentElement);
echo $nodes->item(0)->getAttributeNode(’bgcolor’)->value
. “\n”;
?>
http://www.w3schools.com/xpath/xpath_syntax.asp
*What should go in the ??????? assignment below to create a Zlib-compressed file foo.gz with a compression level of 9?
<?php
$file = ‘????????’;
$fr = fopen($file, ‘wb9′);
fwrite($fr, $data);
fclose($fr);
?>
*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
$file = ‘???????’;
$fr = fopen($file, ‘rb’);
$data = “”;
while(!feof($fr)) {
$data .= fgets($fr, 1024);
}
fclose($fr);
?>
compress.zlib://
*In the event of a PDOException, $info is set with the contents of the $errorInfo property of the exception
an array of error information about the last operation performed by this database handle. The array consists of the following fields:
| Element | Information | 0 | SQLSTATE error code (a five-character alphanumeric identifier defined in the ANSI SQL standard). | 1 | Driver-specific error code. | 2 | Driver-specific error message. |
|---|
*In databases that do not support the AUTO_INCREMENT modifier, you must use a LAST_INSERT_ID(id+1) instead to auto-generate a numeric incrementing key.
*Are following incorrect? Only two are wrong, not four.
a. function c(MyClass $a = new MyClass())
b. function d($a = null)
c. function e(&$a = 30)
d. function a(&$a = array(10,20,30))
e. function b($a = (10 + 2))
b,c,d.
*How does one create a cookie which will exist only until the browser session is terminated?
bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] )
If $expire set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
*If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?
PHP’s Regular Expression Functions (POSIX Extended). regex
POSIX
ereg functions
Perl-style
preg functions.
Perl-compatible syntax using the PCRE functions. These functions support non-greedy matching, assertions, conditional subpatterns, and a number of other features not supported by the POSIX-extended regular expression syntax.This extension maintains a global per-thread cache of compiled regular expressions (up to 4096).
*Which of the following extensions are no longer part of PHP 5 and have been moved to PECL?
w32api, mysql, PDF, ICONV
*Name three new extensions in PHP 5
SimpleXML,PDO, tidy, MySQLi, sqlite, soap
(hash,Reflection,libxml2-based DOM and XSL extensions DOMXML)
*Which of the following SQL statements will improve SQLite write performance?
PRAGMA locking_mode = “Row”;
PRAGMA count_changes = Off;
PRAGMA default_synchronous = Off;
PRAGMA default_synchronous = On;
PRAGMA locking_mode = “Table”;
*What kind of information is acquired when profiling a PHP script?
timer, functions executed
*The method used to create a new node to be added into an XML document using DOM is the DOMDocument->createElement() method
<?php
function func(&$arraykey) {
return $arraykey; // function returns by value!
}
$array = array(’a', ‘b’, ‘c’);
foreach (array_keys($array) as $key) {
$y = &func($array[$key]);
$z[] =& $y;
}
var_dump($z);
?>
// compare to $z[] = ['c', 'c', 'c'];
*Implementing your own PDO class requires which steps from the list below?
extending PDO;
extending PDOStatement;
PDO->setAttribute(PDO::ATTR_STATEMENT_CLASS=>array(string classname, array(mixed constructor_args))
* The implode() function is used to convert an array into a string, maintaining your ability to return the string into an array
Which of the following functions allow you to introspect the call stack during execution of a PHP script?
array debug_backtrace ( void )
generates a PHP backtrace.
Thank you for reading this post. You can now Read Comments (8)
Post Info
This entry was posted on 26 January 2008 8:49 PM and is filed under php tagged with:Technology,web development,zend certification,phpYou can follow any responses to this entry through the Comments Feed. You can Leave A Comment , or A Trackback .
Previous Post: Zend PHP5 certification Exam study review 11: supplementary II »
Next Post: The philosophy of life »
- Review, php|architect’s Guide to Programming with Zend Framework
- Use Writer, the online Darkroom version!
- Learn to Design Web Themes and Templates with New Wiki
- Emergency Aid for Chinese Earthquake: Need 2,6 million Tents right now!
- WordPress problem: Url encoding on Tag’s slug.
- Curl better than simplexml_load_file when web screen scrapping
- How to use SimpleXML parsing XML data with namespace and CDATA
- The philosophy of life
- Zend PHP5 certification Exam study review 12: supplementary III
- Zend PHP5 certification Exam study review 11: supplementary II
chinese












4 February 2008 3:55 AM
Question:
If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?
I think the answer is: preg_*
I found it in php manual:
Note: preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg().
http://uk3.php.net/ereg
5 April 2008 5:14 PM
Hello,
It’s no so obvious (as many other questions in MockExams, heh).
Page 89-90 of Zend PHP5 Certification Study Guide:
“Perl Compatible Regular Expressions (normally abbreviated as “PCRE”) offer a very
powerful string-matching and replacement mechanism that far surpasses anything
we have examined so far.
Regular expressions are often thought of as very complex—and they can be at
times. However, properly used they are relatively simple to understand and fairly
easy to use. Given their complexity, of course, they are also much more computationally
intensive than the simple search-and-replace functions we examined earlier in this chapter. ”
And finally:
“Therefore, you should use them only when appropriate—that is,
when using the simpler functions is either impossible or so complicated that it’s not worth the effort.”
Then, on http://pl.php.net/manual/en/ref.regex.php we can read:
“Tip
PHP also supports regular expressions using a Perl-compatible syntax using the PCRE functions. Those functions support non-greedy matching, assertions, conditional subpatterns, and a number of other features not supported by the POSIX-extended regular expression syntax.”
and because of this complexity of PCRE the implementations of preg_ functions are much more complicated. That’s why using them should be avoided if not necessary.
That’s my opinion and I would choose ereg
13 June 2008 9:33 AM
hey i m now zend certified!!!
http://www.zend.com/store/education/certification/authenticate.php?ClientCandidateID=ZEND005514&RegistrationID=225719929
13 June 2008 8:30 PM
Congratulations!
4 August 2008 1:08 AM
*In databases that do not support the AUTO_INCREMENT modifier, you must use a LAST_INSERT_ID(id+1) instead to auto-generate a numeric incrementing key.
your answer is probably right, But I can’t figure out how LAST_INSERT_ID is working
if I use that query
insert into member (memid,name,firstname,email)
values(LAST_INSERT_ID()+1,’lname’, ‘fname’, ‘test@test.com’)
LAST_INSERT_ID always return 0+1 unless I set SELECT LAST_INSERT_ID(1),LAST_INSERT_ID(2) and so on before each insert query.
could you explain how do you use it, or if you thing it has a better answer
thank you
10 August 2008 8:40 PM
Which RDBMS are you using? If you refer to mysql, I think better use mysql_insert_id().
20 August 2008 12:15 PM
Hi, in MySQL “LAST_INSERT_ID()” will return the last value of the AUTO_INCREMENT column. But, it can also return an expression: LAST_INSERT_ID(expr) in the case thath you don’t have an auto_increment in the transaction (eg: updates, insert … on duplicate key update).
So, the “+1 solution” would be something like this:
INSERT INTO table VALUES(LAST_INSERT_ID(SELECT MAX(id) + 1 FROM table), val1, val2).
In this case the call to the LAST_INSERT_ID is redundant, you could use the subquery result as the value to the insert:
INSERT INTO table VALUES((SELECT MAX(id) + 1 FROM table), val1, val2).
But, you have the possibility to put an expression in there (eg: a stored function which can return an unique -global- id for example).
I have scheduled the Zend Exam on Friday 29th, of this month!!
Wish me luck!
By the way, GREAT POSTS, very VERY helpful!
21 August 2008 9:51 AM
The question
“*In databases that do not support the AUTO_INCREMENT modifier, you must use a LAST_INSERT_ID(id+1) instead to auto-generate a numeric incrementing key.”
I answered “sequence”. A sequence is a database object which stores a sequence of numbers (much like the auto_increment column), but must be called separatly.