Bird
0
0

Which code snippet correctly achieves this?

hard📝 Application Q15 of 15
PHP - Interfaces and Traits
You have two traits, Logger and FileLogger, both with a method log(). You want a class to use FileLogger::log() by default but also keep Logger::log() accessible under the name basicLog(). Which code snippet correctly achieves this?
Ause Logger, FileLogger { FileLogger::log as basicLog; Logger::log insteadof FileLogger; }
Buse Logger, FileLogger { Logger::log insteadof FileLogger; FileLogger::log as basicLog; }
Cuse Logger, FileLogger { log insteadof Logger, FileLogger; Logger::log as basicLog; }
Duse Logger, FileLogger { FileLogger::log insteadof Logger; Logger::log as basicLog; }
Step-by-Step Solution
Solution:
  1. Step 1: Choose default method with insteadof

    To use FileLogger::log() by default, write FileLogger::log insteadof Logger;.
  2. Step 2: Rename other method with as

    To keep Logger::log() accessible as basicLog(), write Logger::log as basicLog;.
  3. Final Answer:

    use Logger, FileLogger { FileLogger::log insteadof Logger; Logger::log as basicLog; } -> Option D
  4. Quick Check:

    Default with insteadof, rename with as [OK]
Quick Trick: Use insteadof for default, as to rename [OK]
Common Mistakes:
  • Swapping traits in insteadof
  • Using as without insteadof
  • Incorrect method renaming syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes