Câu hỏi phỏng vấn PHP
Câu hỏi

What are the main differences between const vs define

Câu trả lời

Here are the main differences between const and define in PHP:

Syntax

  • const is a language construct used to declare constants. The syntax is:
php Copy
const CONSTANT_NAME = value;
  • define is a function used to declare constants. The syntax is:
php Copy
define('CONSTANT_NAME', value);

Scope

  • const constants are visible within the entire scope they are defined in (class, function, file, etc).
  • define constants are global by default, but can be made class-scoped using the optional third parameter.

Evaluation

  • const values are evaluated at compile-time.
  • define values are evaluated at runtime.

Allowed Values

  • const can only be used to store scalar values (int, float, string, bool) and arrays.
  • define can store any...
junior

junior

Gợi ý câu hỏi phỏng vấn

junior

What do we mean by keys and values?

senior

What is the crucial difference between using traits versus interfaces?

senior

Explain the Exception Hierarchy introduced in PHP7

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào