Bird
0
0

Find the error in this code using traits:

medium📝 Debug Q14 of 15
PHP - Interfaces and Traits
Find the error in this code using traits:
trait Logger { function log() { echo 'Log'; } } class File { use Logger } $f = new File(); $f->log();
ACannot instantiate class File
BTrait name Logger is invalid
Clog() method is private
DMissing semicolon after use Logger
Step-by-Step Solution
Solution:
  1. Step 1: Check trait usage syntax

    After use Logger inside class, a semicolon is required.
  2. Step 2: Identify error cause

    Missing semicolon causes syntax error, other options are incorrect.
  3. Final Answer:

    Missing semicolon after use Logger -> Option D
  4. Quick Check:

    Trait use needs semicolon [OK]
Quick Trick: Always add semicolon after trait use inside class [OK]
Common Mistakes:
  • Omitting semicolon after use statement
  • Thinking trait names are invalid
  • Assuming methods are private by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes