Web Designing MCQs

Top 20 MCQ Questions on Namespaces in PHP

Pinterest LinkedIn Tumblr
Here are the collections of the top 20 MCQ questions on namespaces in PHP includes multiple-choice questions on the fundamentals of namespaces in PHP. It includes MCQ questions on defining namespaces and declaring sub-namespaces, using namespaces with aliasing and importing, and about the different name resolution rules.

Read Also: 20 Objective Questions on Classes and Objects in PHP

1) State whether the following statements about namespaces are TRUE or FALSE.
i) Namespace cannot be just a number, it just starts with a letter.
ii) Namespace names are case-insensitive.
A. i-True, ii-False
B. i-False, ii-True
C. i-True, ii-True
D. i-False, ii-False

2) Which of the following types of code are affected by namespaces.
i) Classes
ii) Interfaces
iii) Functions
iv) Constants
A. i, ii and iii only
B. ii, iii and iv only
C. i, ii and iv only
D. All i, ii, iii and iv

3) Which of the following statements about the namespaces are TRUE.
i) Namespaces are declared using the namespace keyword.
ii) A file containing a namespace must declare the namespace at the top of the file before any other code.
iii) Non-PHP code can precede a namespace declaration.
A. i, and ii only
B. i and iii only
C. ii and iii only
D. All i, ii and iii

4) State whether the following statements are TRUE or FALSE.
i) PHP namespaces also contain the ability to specify a hierarchy of namespace names.
ii) The same namespace may be defined in multiple files.
A. i-True, ii-False
B. i-False, ii-True
C. i-True, ii-True
D. i-False, ii-False

5) The … constant is useful for dynamically constructing names.
A. NAMESPACE
B. _NAMESPACE_
C. _ _NAMESPACE_ _
D. _ _NAME_ _

6) The … keyword can be used to explicitly request an element from the current namespace or sub-namespace.
A. request_namespace
B. namespace
C. request
D. current_namespace

7) All versions of PHP that support namespaces support … kinds of aliasing or importing.
A. two
B. three
C. four
D. five

8) In PHP, aliasing is accomplished with the … operator.
A. use
B. define
C. implement
D. require

9) Which of the following are the kinds of aliasing or importing used in PHP.
i) aliasing a class name.
ii) aliasing an interface name.
iii) aliasing a namespace name.
A. i, and ii only
B. i and iii only
C. ii and iii only
D. All i, ii and iii

10) The … keyword must be declared in the outermost scope of a file or inside namespace declarations.
A. use
B. define
C. implement
D. require

11) State whether the following statements about aliasing and importing are TRUE or FALSE.
i) Importing is done at compile time and not runtime.
ii) In PHP, aliasing is accomplished with the implement operator.
A. i-True, ii-False
B. i-False, ii-True
C. i-True, ii-True
D. i-False, ii-False

12) For the namespace used on PHP … is an identifier without a namespace separator.
A. qualified name
B. unqualified name
C. fully qualified name
D. relative name

13) For the namespace used on PHP … is an identifier with a namespace separator.
A. qualified name
B. unqualified name
C. fully qualified name
D. relative name

14) … is an identifier with a namespace separator that begins with a namespace separator.
A. Qualified name
B. Unqualified name
C. Fully qualified name
D. Relative name

15) Which of the following statements about name resolution rules are TRUE.
i) Fully qualified names always resolve to the name without leading namespace separator.
ii) Relative names always resolve to the name with namespace replaced by the current namespace.
A. i-only
B. ii-only
C. Both i and ii
D. None of the above

16) For …, if no import rule applies, the current namespace is prepended to the name.
A. qualified names
B. unqualified names
C. fully qualified names
D. relative names

17) For …, if no import rule applies and the name refers to a class-like symbol, the current namespace is prepended.
A. qualified names
B. unqualified names
C. fully qualified names
D. relative names

18) … are not allowed in namespace declarations, because such constructs are interpreted as relative namespaces expressions.
A. Qualified name
B. Unqualified name
C. Fully qualified name
D. Relative name

19) Which of the following statements about namespaces are TRUE.
i) Multiple namespaces may be declared in the same file.
ii) PHP code may exist outside of the namespace brackets except for an opening declare statement.
iii) Classes, functions, and constants being imported from the same namespace can be grouped together in a single-use statement.
A. i, and ii only
B. i and iii only
C. ii and iii only
D. All i, ii and iii

20) For …, if no import rule applies and the name refers to a function or constant and the code is outside the global namespace.
A. qualified names
B. unqualified names
C. fully qualified names
D. relative names

Answers:

  1. C. i-True, ii-True
  2. D. All i, ii, iii and iv
  3. A. i, and ii only
  4. C. i-True, ii-True
  5. C. _ _NAMESPACE_ _
  6. B. namespace
  7. B. three
  8. A. use
  9. D. All i, ii and iii
  10. A. use
  11. A. i-True, ii-False
  12. B. unqualified name
  13. A. qualified name
  14. C. Fully qualified name
  15. C. Both i and ii
  16. A. qualified names
  17. B. unqualified names
  18. C. Fully qualified name
  19. B. i and iii only
  20. B. unqualified names

Read Next: Top 20 MCQ Questions on Error Handling in PHP

Author

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Comments are closed.