Задачи из онлайн теста по PHP 5

MARDEN

Новичок
Задачи из онлайн теста по PHP 5

На днях удалось получить доступ к одному известному онлайн тесту. Столкнулся с некоторыми вопросами, на которые не удалось ответить со 100%-й уверенностью. Поэтому прошу откликнуться мастеров php дабы помочь решить некоторые задачи и развеять сомнения.
Примечания:
- Там, где нет пометок, нужно выбрать один вариант. В других случаях, если отмечено, может быть несколько правильных ответов или требуется самому вписать ответ.
- Огромная просьба всем откликнувшимся аргументировать свои ответы.

1(1). When implementing a permissions system for your 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. Sessions should be cleared of all data and re-populated
D. The session key should be regenerated
E. The session should be destroyed

2(12). When running PHP in a shared host environment, what is the major security concern when it comes to session data?
A. Sessions on shared hosts are easily hijacked by outside malicious users
B. All of the above
C. You cannot use a custom data store in shared hosts
D. Session data stored in the file system can be read by other scripts on the same shared host
E. Users outside the shared host can access any site which created a session for them

3(20). Consider the following series of classes and interfaces
PHP:
<?php
 interface MyInterface {
 public function getTitleAndAuthor();
}

class MyClass {
 private $_author;
 private $_title;

 public function getAuthor() {
 _return $this->_author;
 }

 public function getTitle() {
 _return $this->_title;
 }
}

class MyClass2 {
 private $_instance;

 public function __construct(MyClass $a) {
 _$this->_instance = $a;
 }

 public function getTitleAndAuthor() {
 _$retval = array(
 _ 'title' => $this->_instance->getTitle(),
 _ 'author' => $this->_instance->getAuthor()
 _);
 _return $retval; 
 }
}

class MyClass3 {
 public function doSomething(MyInterface $instance) {
 _$value = $instance->getTitleAndAuthor();
 }
}
?>
MyClass2 is an example of the ________ design pattern.
Вписать нужный ответ.

4(21). The ____ construct is particularly useful to assign your own variable names to values within an array.
A. array_get_variables
B. current
C. each
D. import_variables
E. list

5(41). Which from the following list is not an approrpiate use of an array?
A. As a list
B. All of these uses are valid
C. As a Lookup Table
D. A Stack
E. As a hash table

6(46). Which of the following are examples of the new engine executor models available in PHP 5?
Выбрать 3 ответа.
A. Switch
B. Conditional
C. Goto
D. Call
E. Dynamic

7(55). 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.
Вписать нужный ответ.

8(59). The ________ function is used to generate a file resource in the file system with a randomly-generated filename to be used as temporary storage
Вписать нужный ответ.

9. The _________ pattern is useful for an object which can be traversed as a list, implemented in PHP by an interface of the same name.
Вписать нужный ответ.

Заранее спасибо!
 

MARDEN

Новичок
Апокалипсис
Читай пост внимательно. Никто тебя не заставляет помогать другим.

Alexandre
Это не Brainbench. Хотя какая в принципе разница?

whirlwind
Спасибо. Правда, про facade pattern слышу впервые.
 

crocodile2u

http://vbolshov.org.ru
1(1). When implementing a permissions system for your 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. Sessions should be cleared of all data and re-populated
D. The session key should be regenerated
E. The session should be destroyed

Имхо, E. The session should be destroyed - действительно, надо уничтожать сессию при выходе пользователя.

-----------------------------------------

2(12). When running PHP in a shared host environment, what is the major security concern when it comes to session data?
A. Sessions on shared hosts are easily hijacked by outside malicious users
B. All of the above
C. You cannot use a custom data store in shared hosts
D. Session data stored in the file system can be read by other scripts on the same shared host
E. Users outside the shared host can access any site which created a session for them

Д. Хотя это не всегда правда, но это дейтсвительно случается, когда плохие админы.

-----------------------------------------
4(21). The ____ construct is particularly useful to assign your own variable names to values within an array.
A. array_get_variables
B. current
C. each
D. import_variables
E. list

list($id, $name) = array(111, "foo");

-----------------------------------------
5(41). Which from the following list is not an approrpiate use of an array?
A. As a list
B. All of these uses are valid
C. As a Lookup Table
D. A Stack
E. As a hash table

Имхо, B. All of these uses are valid

-----------------------------------------
6(46). Which of the following are examples of the new engine executor models available in PHP 5?
Выбрать 3 ответа.
A. Switch
B. Conditional
C. Goto
D. Call
E. Dynamic

vbolshov@vbolshov-desktop:~/src/php/php-5.2.5$ ./configure --help|less
...
--with-zend-vm=TYPE Set virtual machine dispatch method. Type is
one of CALL, SWITCH or GOTO [TYPE=CALL]

-----------------------------------------
8(59). The tmpfile() function is used to generate a file resource in the file system with a randomly-generated filename to be used as temporary storage
Вписать нужный ответ.

-----------------------------------------
9. The Iterator pattern is useful for an object which can be traversed as a list, implemented in PHP by an interface of the same name.
Вписать нужный ответ.

-----------------------------------------
C 7м вопросом затрудняюсь ответить.

Надеюсь, мои ответы натолкнут тебя на нужное чтение и мысли.
 

MARDEN

Новичок
crocodile2u
Спасибо! Однако я не совсем согласен с первым ответом. Мне кажется, что там ответ D - регенарация ключа - для борьбы с session fixation.
 

Wicked

Новичок
У меня получилось почти как у crocodile2u, кроме:
1. какой-то расплывчатый вопрос. Ответ либо A, либо D (регенерация при хорошем использовании сессий - более частая операция, чем остальные, но даже оно на "always" как-то не тянет.
2. b, потому что все варианты c, d, e вероятны.
7. stream?
и еще я хз про что идет речь в пункте 6 :)
 

crocodile2u

http://vbolshov.org.ru
Wicked

Насчет сессий: вопрос, и правда, некорректный. Я лично сомневаюсь в том, что мой ответ правильный, почему и пометил его ИМХОй.

насчет шаред-хостов: не соглашусь, читай внимательнее - речь в двух пунктах идет об "аутсайд юзерз". А уж насчет "кастом дата стор" - с какой стати на щаред хосте это должно стать большей проблемой, чем на выделенном? Хочешь - файлы, хочешь - БД... Шаред хост - это конечно всегда менее безопасно, чем свой выделенный, но чтобы "easily" чего-то там сломать на твоем сайте - именно по причине "шаред" - это уж слишком...

Про п. 6. PHP5 может быть собран с разными "моделями". GOTO вроде самая быстрая. Чем СВИТЧ и ГОУТУ хуже КОЛЛ - сказать не могу. КОЛЛ - вроде бы самая медленная. Думается, дело в стабильности, но здесь лучше Тони объяснит, если заглянет в эту ветку.
 

MARDEN

Новичок
Wicked, crocodile2u
Спасибо за ваши комментарии! Согласен, что постановка некоторых вопросов ставит в тупик, но увы, ничего с этим не поделаешь.
 
Сверху