You have a PHP script and you need to access a constant of a class. How would you do this?

  • ClassName::CONSTANT_NAME
  • $class->CONSTANT_NAME
  • self::CONSTANT_NAME
  • $this->CONSTANT_NAME
To access a constant of a class in PHP, you can use the class name followed by the scope resolution operator :: and the constant name. For example: ClassName::CONSTANT_NAME This allows you to directly reference the value of a constant defined within a class without the need for object instantiation. The self keyword can also be used to access the constant within the class itself. To learn more, visit: http://php.net/manual/en/language.oop5.constants.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *