Hướng dẫn check constant is defined php - kiểm tra hằng số được xác định php

(Php 4, Php 5, Php 7, Php 8)

được xác định - kiểm tra xem một hằng số có tên đã cho có tồn tại khôngChecks whether a given named constant exists

Sự mô tả

được xác định (chuỗi $constant_name): bool(string $constant_name): bool

Ghi chú::

Nếu bạn muốn xem nếu một biến tồn tại, hãy sử dụng isset () như đã xác định () chỉ áp dụng cho hằng số. Nếu bạn muốn xem một hàm có tồn tại hay không, hãy sử dụng function_exists ().isset() as defined() only applies to constants. If you want to see if a function exists, use function_exists().

Thông số

constant_name

Tên liên tục.

Trả về giá trị

Trả về true Nếu hằng số được đặt tên được cho bởi constant_name đã được xác định, false nếu không.true if the named constant given by constant_name has been defined, false otherwise.

Ví dụ

Ví dụ #1 Kiểm tra hằng số

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>

Xem thêm

  • Xác định () - Xác định một hằng số được đặt tên
  • hằng số () - Trả về giá trị của một hằng số
  • get_defined_constants () - Trả về một mảng kết hợp với tên của tất cả các hằng số và giá trị của chúng
  • function_exists () - return true nếu hàm đã cho đã được xác định
  • Phần trên các hằng số

Daniel tại Neville Dot TK ¶

14 năm trước

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)

defined

('CONSTANT') or define('CONSTANT', 'SomeDefaultValue');?>

Dan.

Aschmidt tại Anamera Dot Net

5 năm trước

constant_name0

constant_name1

constant_name2

constant_name3

constant_name4

constant_name5

Tris+PHP tại tfconsulting dot com dot au ¶

13 năm trước

constant_name6

constant_name7

constant_name8

constant_name9

true0

true1

constant_name5

r dot hartung tại Roberthartung dot de ¶

12 năm trước

true3

true4

true5

true6

Lars Lernestal ¶

11 năm trước

true7

true8

constant_name5

Shaun H ¶

14 năm trước

constant_name0

constant_name1

constant_name5

Aschmidt tại Anamera Dot Net

5 năm trước

constant_name3

constant_name4

constant_name5

constant_name5

Tris+PHP tại tfconsulting dot com dot au ¶

13 năm trước

constant_name7

constant_name8

constant_name5

r dot hartung tại Roberthartung dot de ¶

13 năm trước

false0

false2

false3

r dot hartung tại Roberthartung dot de ¶

12 năm trước

false4

false5

false6

false7

Lars Lernestal ¶

12 năm trước

false8

false9

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
0

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
1

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
2

Lars Lernestal ¶

5 năm trước

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
3

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
4

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
5

Tris+PHP tại tfconsulting dot com dot au ¶

13 năm trước

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
6

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
7

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
8

/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo 
TEST;
}
?>
9

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)0

constant_name5

r dot hartung tại Roberthartung dot de ¶

12 năm trước

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)2

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)3

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)4

constant_name5

Lars Lernestal ¶

11 năm trước

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)6

My preferred way of checking if a constant is set, and if it isn't - setting it (could be used to set defaults in a file, where the user has already had the opportunity to set their own values in another.)7

constant_name5

Làm thế nào để bạn kiểm tra một hằng số?

Để kiểm tra xem hằng số có được xác định sử dụng hàm được xác định không.Lưu ý rằng chức năng này không quan tâm đến giá trị của không đổi, nó chỉ quan tâm nếu không đổi tồn tại hay không.Ngay cả khi giá trị của hằng số là null hoặc false, hàm vẫn sẽ trả về true.use the defined function. Note that this function doesn't care about constant's value, it only cares if the constant exists or not. Even if the value of the constant is null or false the function will still return true .

Làm thế nào là xác định liên tục trong tập lệnh PHP?

Một hằng số là một định danh (tên) cho một giá trị đơn giản.Giá trị không thể được thay đổi trong tập lệnh.Một tên hằng số hợp lệ bắt đầu bằng chữ cái hoặc dấu gạch dưới (không có giá nào trước tên hằng số).Lưu ý: Không giống như các biến, hằng số tự động toàn cầu trên toàn bộ tập lệnh.an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.

DEFINE () trong PHP là gì?

định nghĩa () hàm trong hàm dEfine () xác định một hằng số.defines a constant.

Các hằng số toàn cầu có phải là PHP không?

Giống như Superglobals, phạm vi của một hằng số là toàn cầu.Các hằng số có thể được truy cập từ bất cứ nơi nào trong một kịch bản mà không liên quan đến phạm vi.the scope of a constant is global. Constants can be accessed from anywhere in a script without regard to scope.