Bird
0
0

Which of the following is the correct syntax to access a class constant named VERSION in PHP?

easy📝 Syntax Q12 of 15
PHP - Classes and Objects
Which of the following is the correct syntax to access a class constant named VERSION in PHP?
AClassName::VERSION
B$obj->VERSION
CClassName->VERSION
D$obj:VERSION
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to access class constants

    Class constants are accessed using the scope resolution operator :: with the class name, like ClassName::CONSTANT.
  2. Step 2: Identify incorrect options

    $obj->VERSION tries to access a property, not a constant; ClassName->VERSION is invalid syntax; $obj:VERSION uses single colon which is invalid syntax.
  3. Final Answer:

    ClassName::VERSION -> Option A
  4. Quick Check:

    Access constants with ClassName::CONSTANT [OK]
Quick Trick: Use ClassName::CONSTANT to access class constants [OK]
Common Mistakes:
  • Using object operator -> instead of ::
  • Trying to access constants as properties
  • Confusing variable and class name usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes