Zend Certified PHP Engineer (ZCE) PHP 7.1 — Question 1
Youd like to use the class MyDBConnection thats 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?
Answer options
- A. Import the MyGreatFramework namespace
- B. Import the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace
- C. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer\MyDBConnection to a shorter name
- D. Alias MyGreatFramework\MyGreatDatabaseAbstractionLayer to a shorter name
Correct answer: B
Explanation
The correct answer is B because importing the entire MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace allows direct access to MyDBConnection without additional qualifiers. Option A would not provide access to MyDBConnection, while options C and D involve aliasing, which is not necessary for minimizing typing in this context.