200-550

200-550 practice questions, page 5 of 9, with answer review and explanations.

Question 21

When would you use classes and when would you use namespaces?

  1. Use classes to encapsulate code and represent objects, and namespaces to avoid symbol name collisions
  2. Use classes for performance-sensitive code, and namespaces when readability matters more
  3. Use namespaces for performance-sensitive code, and classes when readability matters more
  4. Always use them; namespaces are always superior to classes

Question 22

Which of these elements can be encapsulated by namespaces and made accessible from the outside?

  1. Only classes
  2. Classes, functions and constants
  3. Classes, functions, constants and variables

Question 23

You'd like to use the class MyDBConnection that's defined in the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace, but you want to minimize *as much as possible* the length of the class name you have to type. What would you do?

  1. Import the MyGreatFramework namespace
  2. Import the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace
  3. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer\MyDBConnection to a shorter name
  4. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer to a shorter name

Question 24

How should you track errors on your production website?

  1. Enabling display_errors
  2. Enabling log_errors
  3. Having a site-wide exception handler
  4. Setting error_reporting to E_ALL & ~E_NOTICE

Question 25

What would be the output of the following code? namespace MyFramework\DB; class MyClass { static function myName() { return __METHOD__; } } print MyClass::myName();

  1. MyFramework\DB\myName
  2. MyFramework\DB\MyClass\myName
  3. MyFramework\DB\MyClass::myName
  4. MyClass::myName