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

middle

Is there any reason to use strcmp() for strings comparison?

middle

What are some of the big changes PHP has gone through in the past few years?

junior

What do we mean by keys and values?

Bình luận

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

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