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:
const CONSTANT_NAME = value;
  • define is a function used to declare constants. The syntax is:
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

Is multiple inheritance supported in PHP?

senior

Store an array as JSON or as a PHP serialized array?

junior

Is there a difference between isset and !empty ?

Bình luận

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

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