Bird
0
0

Which of the following is the correct syntax to declare an empty class named Person in PHP?

easy📝 Syntax Q12 of 15
PHP - Classes and Objects
Which of the following is the correct syntax to declare an empty class named Person in PHP?
Aclass Person() { }
Bclass Person[] { }
Cclass Person {};
Dclass Person { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP class declaration syntax

    PHP classes are declared with the keyword class, the class name, and curly braces without parentheses or brackets.
  2. Step 2: Check each option

    class Person { } uses class Person { }, which is correct. class Person() { } wrongly uses parentheses, B uses brackets, and D adds a semicolon after braces which is unnecessary.
  3. Final Answer:

    class Person { } -> Option D
  4. Quick Check:

    Empty class = class Name { } [OK]
Quick Trick: No parentheses or brackets after class name [OK]
Common Mistakes:
  • Adding parentheses after class name
  • Using square brackets after class name
  • Adding unnecessary semicolon after class braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes