1. Which function is used to define a constant in PHP?
Answer:
Explanation:
The define() function is used to define a constant in PHP.
2. Once a constant is defined in PHP, can its value be changed?
Answer:
Explanation:
The value of a constant in PHP cannot be changed once it is set.
3. Which of the following is the correct way to check if a constant is defined in PHP?
Answer:
Explanation:
The defined() function is used to check whether a constant is defined.
4. How are constants accessed in PHP?
Answer:
Explanation:
Constants are accessed directly by their name without any $ symbol.
5. What is the output of the following PHP code if the constant 'MAX' is not defined? defined('MAX') ? 'Yes' : 'No';
Answer:
Explanation:
The defined() function returns false if the constant is not defined, so the output will be 'No'.
6. Which of the following is true about magic constants in PHP?
Answer:
Explanation:
Magic constants are predefined by PHP, and their value changes based on where they are used.
7. What does the PHP constant PHP_VERSION represent?
Answer:
Explanation:
The PHP_VERSION constant contains the current version of PHP.
8. Which magic constant returns the function or method name from which it is called?
Answer:
Explanation:
The __METHOD__ magic constant returns the name of the method, whereas __FUNCTION__ returns the name of the function.
9. Can you create an array as a constant in PHP?
Answer:
Explanation:
As of PHP 7.0, it is possible to define an array as a constant using the define() function.
10. What is the scope of a constant in PHP?
Answer:
Explanation:
Constants in PHP are automatically global and can be accessed from any part of the script.
Comments
Post a Comment