PHP - Interfaces and TraitsWhich of the following is the correct way to declare an interface in PHP?Aclass MyInterface { public function doSomething() {} }Binterface MyInterface { public function doSomething(); }Cinterface MyInterface() { function doSomething(); }Dinterface MyInterface { function doSomething() {} }Check Answer
Step-by-Step SolutionSolution:Step 1: Recall PHP interface syntaxInterfaces use the keyword 'interface' followed by the name and method declarations without bodies.Step 2: Check method declaration rulesMethods in interfaces must be declared without code (no braces), only the signature.Final Answer:interface MyInterface { public function doSomething(); } -> Option BQuick Check:Interface methods have no body [OK]Quick Trick: Interface methods have no code blocks {} [OK]Common Mistakes:Adding method bodies inside interfacesUsing parentheses after interface nameDeclaring interfaces as classes
Master "Interfaces and Traits" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Array Functions - Why array functions matter - Quiz 13medium Array Functions - Compact and extract functions - Quiz 10hard Array Functions - Array map function - Quiz 13medium Classes and Objects - Destructor method - Quiz 11easy Classes and Objects - Destructor method - Quiz 6medium Classes and Objects - Static properties and methods - Quiz 14medium Classes and Objects - Why OOP is needed in PHP - Quiz 3easy Inheritance and Polymorphism - Instanceof operator - Quiz 11easy Interfaces and Traits - Multiple interface implementation - Quiz 13medium Sessions and Cookies - Starting and using sessions - Quiz 14medium