Programming Languages PHP Objective
Sep 23, 2025

What is the correct way to implement a PHP 8+ union type for a parameter that accepts string or int?

Choose the correct answer:
A) function test(string|int $param)
B) function test(string,int $param)
C) function test(string||int $param)
D) function test(string&int $param)
Detailed Explanation

Explanation: PHP 8.0 introduced union types using the pipe (|) operator. This allows a parameter to accept multiple types. Union types provide better type safety while maintaining flexibility.

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback