nerdexam
Zend

200-710 · Question #144

Type hinting in PHP allows the identification of the following variable types: (Choose 2)

The correct answer is C. Array D. Any class or interface type. PHP's type hinting system - particularly in PHP 5.x - only natively supported array (introduced in PHP 5.1) and class/interface names as valid type hints for function parameters, making C and D the correct choices for that context. Why A and B are wrong: Scalar types like…

Object-Oriented Programming

Question

Type hinting in PHP allows the identification of the following variable types: (Choose 2)

Options

  • AString
  • BInteger
  • CArray
  • DAny class or interface type
  • EAll of the above

How the community answered

(31 responses)
  • A
    10% (3)
  • B
    3% (1)
  • C
    81% (25)
  • E
    6% (2)

Explanation

PHP's type hinting system - particularly in PHP 5.x - only natively supported array (introduced in PHP 5.1) and class/interface names as valid type hints for function parameters, making C and D the correct choices for that context.

Why A and B are wrong: Scalar types like string and int (integer) were not valid type hints in PHP 5.x - attempting to use them would throw a fatal error. Scalar type declarations were only introduced in PHP 7.0, so this question targets the pre-7.0 behavior.

Why E is wrong: Since A (String) and B (Integer) are not supported in the PHP version this question targets, "All of the above" cannot be correct.

Memory tip: Think of PHP 5.x type hints as only accepting "complex" or "structured" types - things with a defined structure like an array or a class/interface. Primitive scalars (string, int, float, bool) had to wait for PHP 7. A handy phrase: "PHP 5 hints at arrays and classes; PHP 7 hints at scalars too."

Topics

#type hinting#arrays#interfaces#type declarations

Community Discussion

No community discussion yet for this question.

Full 200-710 Practice