Recall & Review
beginner
What is a constant in a PHP class?
A constant in a PHP class is a fixed value that cannot be changed once set. It is defined using the <code>const</code> keyword and is accessed without creating an object.Click to reveal answer
beginner
How do you define a constant inside a PHP class?
Use the <code>const</code> keyword followed by the constant name and value. For example: <code>const PI = 3.14;</code>Click to reveal answer
beginner
How do you access a class constant from outside the class?Use the class name followed by the scope resolution operator <code>::</code> and the constant name. For example: <code>ClassName::CONSTANT_NAME</code>Click to reveal answer
beginner
Can class constants be changed after they are defined?No, class constants cannot be changed after they are defined. They are fixed values throughout the program.Click to reveal answer
intermediate
What is the difference between a class constant and a class property?A class constant is a fixed value defined with <code>const</code> and cannot change. A class property is a variable that can hold different values and can be changed.Click to reveal answer
How do you define a constant inside a PHP class?
✗ Incorrect
Class constants are defined using the
const keyword inside the class.How do you access a class constant from outside the class?
✗ Incorrect
Class constants are accessed with the class name and the scope resolution operator
::.Can you change the value of a class constant after it is set?
✗ Incorrect
Class constants cannot be changed once defined; they are immutable.
Which keyword is NOT used to define a class constant?
✗ Incorrect
var is used for properties, not constants.What is the correct way to define a constant named VERSION with value '1.0' inside a class?
✗ Incorrect
Class constants are defined with
const followed by the name and value.Explain how to define and access a constant inside a PHP class.
Think about how constants are fixed and how you call them without creating an object.
You got /3 concepts.
Describe the difference between a class constant and a class property in PHP.
Consider mutability and how you use each in a class.
You got /4 concepts.