Zend PHP5 认证考试研究之12: 附三

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.



感谢您阅读本文章。您现在可以 Read Comments (11)

日志信息

本日志发布于   1月 26, 2008   8:49 下午   发布在   php   标记为:,,,

你可以跟进任何对此文章的回复通过 Comments Feed. 你可以 留一个评论 ,或 一个 Trackback .



前一日志 Zend PHP5 认证考试研究之11: 附二 »
下一日志 关于生活的哲学 »

阅读更多

相关阅读:

11 回复 到 “ Zend PHP5 认证考试研究之12: 附三

  • 1
    Piotr Lewandowski
    2月 4, 2008 3:55 上午

    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

  • 2
    Krzysztof Ryba
    4月 5, 2008 5:14 下午

    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

  • 3
    Heena
    6月 13, 2008 9:33 上午

    hey i m now zend certified!!!

    http://www.zend.com/store/education/certification/authenticate.php?ClientCandidateID=ZEND005514&RegistrationID=225719929

  • 4
    admin
    6月 13, 2008 8:30 下午

    Congratulations! :)

  • 5
    Athanas
    8月 4, 2008 1:08 上午

    *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

  • 6
    admin
    8月 10, 2008 8:40 下午

    Which RDBMS are you using? If you refer to mysql, I think better use mysql_insert_id().

  • 7
    Andrés G. Montañez
    8月 20, 2008 12:15 下午

    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!

  • 8
    Andrés G. Montañez
    8月 21, 2008 9:51 上午

    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.

  • 9
    tjmcd1963
    10月 5, 2008 4:30 上午

    Krzysztof Ryba Said,
    “That’s my opinion and I would choose ereg”

    …and Krzysztof makes a good arguement HOWEVER…
    Having taken the practice test twice now (wherein the same question came up on both ocasions) where upon I did answer
    “preg_* regular expression functions” and on both occasions I scored “EXCELENT” on the
    String Manipulation and Regular Expressions section of the test. That said, seeing as there were so few regex questions on either test, do you think it likely that I got it wrong twice and still scored EXCELLENT both times ????

  • 10
    admin
    10月 5, 2008 2:27 下午

    Um. Maybe you are right. But, actually, the purpose of my posts is not to tell which are the correct answers to the exam test. I just want to share some of my information to the users. I will be glad if these have any help for my readers :).

    Personally, I think I will choose preg_*.

  • 11
    tjmcd1963
    10月 9, 2008 1:31 上午

    *The method used to create a new node to be added into an XML document using DOM is the ___________ method.
    Ambiguous qestion as it fails to specify what kind of node.
    e.g. the correct answer COULD be any of …
    DomDocument->create_cdata_section
    — Creates new cdata node
    DomDocument->create_comment
    — Creates new comment node
    DomDocument->create_element_ns
    — Creates new element node with an associated namespace
    DomDocument->create_element
    — Creates new element node
    DomDocument->create_processing_instruction
    — Creates new PI node
    DomDocument->create_text_node
    — Creates new text node
    However I AM inclined to agree that
    “DomDocument->create_element” is the answer they are looking for.



留一个评论

注意:任何可以被发表的评论仅仅由于本站所有者同意这样做,任何评论都可能由本站所有者处于任何理由而删除。