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:
- C. i-True, ii-True
- D. All i, ii, iii and iv
- A. i, and ii only
- C. i-True, ii-True
- C. _ _NAMESPACE_ _
- B. namespace
- B. three
- A. use
- D. All i, ii and iii
- A. use
- A. i-True, ii-False
- B. unqualified name
- A. qualified name
- C. Fully qualified name
- C. Both i and ii
- A. qualified names
- B. unqualified names
- C. Fully qualified name
- B. i and iii only
- B. unqualified names
Read Next: Top 20 MCQ Questions on Error Handling in PHP
Comments are closed.