Bird
0
0

Which syntax correctly defines a class named 'Person' in PHP?

easy📝 Syntax Q3 of 15
PHP - Classes and Objects
Which syntax correctly defines a class named 'Person' in PHP?
A<?php new Person { } ?>
B<?php function Person() { } ?>
C<?php class Person { } ?>
D<?php var Person = class() { } ?>
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP class syntax

    In PHP, a class is defined using the keyword 'class' followed by the class name and curly braces.
  2. Step 2: Evaluate each option

    <?php class Person { } ?> uses correct syntax. <?php function Person() { } ?> uses 'function' which is wrong. <?php new Person { } ?> uses 'new' incorrectly. <?php var Person = class() { } ?> uses invalid syntax.
  3. Final Answer:

    <?php class Person { } ?> -> Option C
  4. Quick Check:

    Class syntax = class keyword + name + braces [OK]
Quick Trick: Use 'class ClassName { }' to define a class in PHP [OK]
Common Mistakes:
  • Using 'function' instead of 'class'
  • Trying to instantiate with 'new' in definition
  • Incorrect variable assignment for class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes