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?
Use classes to encapsulate code and represent objects, and namespaces to avoid symbol name collisions
Use classes for performance-sensitive code, and namespaces when readability matters more
Use namespaces for performance-sensitive code, and classes when readability matters more
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?
Only classes
Classes, functions and constants
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?
Import the MyGreatFramework namespace
Import the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace
Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer\MyDBConnection to a shorter name
Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer to a shorter name
Question 24
How should you track errors on your production website?
Enabling display_errors
Enabling log_errors
Having a site-wide exception handler
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();