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
Loading...
Related Quiz
- Which of the following are valid ways to define a string in PHP?
- What are the PHP mail functions used for?
- You have a for loop in your PHP script that is not terminating as expected. What could be the possible reasons and how would you debug this?
- Which of the following are ways to handle sessions in PHP?
- You are writing a PHP script and you need to check if a string matches a specific pattern. How would you do this using Regular Expressions in PHP?