In PHP, which keyword is used to define a constant?

Prepare for the Zend Certified PHP Engineer Exam with our comprehensive test, featuring flashcards and multiple choice questions. Each question comes with detailed hints and explanations. Ensure you're ready for your exam!

In PHP, the keyword used to define a constant is "define". This function allows you to create a constant that cannot be changed once it has been set. Unlike variables, which can be modified, constants are immutable and can be accessed globally throughout the script.

When using "define", you can specify the name of the constant and its value. For example, using define('MY_CONSTANT', 'value');, you create a constant named MY_CONSTANT with a value of 'value'. Additionally, the constant's name is case-sensitive if defined in all uppercase, which is a common practice to signify constants.

While "const" is also a valid keyword for defining constants, it is used in a different context—specifically, within classes for class constants. Therefore, "define" is the primary method for defining constants in the broader scope of PHP.

The other options do not serve as valid keywords in PHP for defining constants, which further highlights why "define" is the appropriate choice.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy