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 are the differences between die() and exit() functions in PHP?

junior

Is there a difference between isset and !empty ?

junior

Can you extend a Final defined class?

Bình luận

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

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