Recall & Review
beginner
What is the basic syntax to declare a class in PHP?Use the <code>class</code> keyword followed by the class name and curly braces. Example:<br><pre>class MyClass {<br> // properties and methods<br>}</pre>Click to reveal answer
beginner
What keyword is used to create a class in PHP?The keyword <code>class</code> is used to declare a class in PHP.Click to reveal answer
beginner
Can a PHP class contain properties and methods? Give a simple example.Yes, a PHP class can have properties (variables) and methods (functions). Example:<br><pre>class Car {<br> public $color;<br> function drive() {<br> echo "Driving";<br> }<br>}</pre>Click to reveal answer
beginner
Is it necessary to end a PHP class declaration with a semicolon?No, PHP class declarations do not end with a semicolon after the closing brace.Click to reveal answer
beginner
How do you name a class in PHP? Are there any rules?Class names should start with a letter or underscore, followed by letters, numbers, or underscores. They are case-insensitive but it's common to use PascalCase. Example: <code>class MyClassName {}</code>Click to reveal answer
Which keyword is used to declare a class in PHP?
✗ Incorrect
The
class keyword is used to declare a class in PHP.What symbol is used to enclose the body of a PHP class?
✗ Incorrect
Curly braces
{} are used to enclose the class body.Which of the following is a valid PHP class name?
✗ Incorrect
Class names can start with a letter or underscore, but not a number or hyphen.
_UserProfile is valid.Do you need a semicolon after the closing brace of a PHP class declaration?
✗ Incorrect
No semicolon is needed after the closing brace of a class declaration.
Which of these can be inside a PHP class?
✗ Incorrect
A PHP class can contain both properties (variables) and methods (functions).
Explain how to declare a simple class in PHP including properties and methods.
Think about the structure: keyword, name, then body with variables and functions.
You got /5 concepts.
What are the rules for naming a class in PHP?
Consider what characters are allowed and common naming styles.
You got /5 concepts.