Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Interfaces and Traits
What will be the output of this PHP code?
interface Writer {
  public function write(string $text);
}

class FileWriter implements Writer {
  public function write(string $text) {
    return strtoupper($text);
  }
}

$fw = new FileWriter();
echo $fw->write('hello');
AHELLO
BError: Missing return type
Chello
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Check method implementation

    FileWriter implements write() returning uppercase text.
  2. Step 2: Call write('hello')

    Returns 'HELLO' which is echoed.
  3. Final Answer:

    HELLO -> Option A
  4. Quick Check:

    Method returns uppercase string = HELLO [OK]
Quick Trick: Interface methods can return transformed data [OK]
Common Mistakes:
  • Expecting original text output
  • Confusing return type errors
  • Ignoring method return value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes