How does the PHP version affect the ability to access constants?
The PHP version can affect the ability to access constants if the constant is defined using the `const` keyword inside a class. In PHP 5, constants defined in classes cannot be accessed using the `::` syntax outside of the class definition. This limitation was removed in PHP 7, allowing constants defined in classes to be accessed using the `::` syntax from outside the class.
class MyClass {
const MY_CONSTANT = 'Hello World';
}
// Accessing constant in PHP 7+
echo MyClass::MY_CONSTANT;
Related Questions
- Is it possible to set a timer to automatically log out a user if their session is inactive for a certain amount of time in PHP?
- How can missing semicolons at the end of lines affect PHP code execution?
- What are common issues with character encoding in PHP when dealing with strings containing special characters like umlauts?