1. Home
  2. Computer Science MCQs
  3. PHP
  4. How do you define a constant in PHP?

Added 23 Jan 2024

How do you define a constant in PHP?

  1. define_constant()
  2. create_constant()
  3. const()
  4. define() Correct answer

Correct answer

D. define()

17 views

MCQSEXAM

Explanation

define() creates a constant at run time, as in define("SITE_NAME", "MCQsExam");. The value cannot be changed afterwards, and constants are written without a leading $.

PHP also provides the const keyword for constants declared at compile time, including inside classes, but it is a keyword rather than the function const() shown in the options.

Keep preparing with more Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs