Home > Backend Development > PHP Problem > Can php delete constants?

Can php delete constants?

coldplay.xixi
Release: 2023-03-03 19:34:01
Original
3657 people have browsed it

PHP cannot delete constants, reasons: 1. When assigning a constant to a variable, it actually assigns a value, but it is still a constant; 2. Once a constant is defined, it cannot be replaced

Can php delete constants?

#php cannot delete constants, only variables.

Assigning a constant to a variable is actually assigning a value, but it is still a constant.

All constants cannot be deleted.

And the constants you define cannot be changed, they are fixed.

Evidence: define defines a constant define(constant name, value);

Proof 1: The constant cannot be deleted

<?php
define(&#39;abc&#39;,&#39;abc&#39;);
unset(abc);
?>
Copy after login

Execution result: Syntax Error

Parse error: syntax error, unexpected &#39;)&#39;, expecting T_PAAMAYIM_NEKUDOTAYIM in C:\wamp\www\Untitled-1.php on line 11
Copy after login

Certificate 2: Once a constant is defined, it cannot be replaced

<?php
define(&#39;abc&#39;,&#39;abc&#39;);
echo abc;
define(&#39;abc&#39;,&#39;bcd&#39;);
echo abc;
?>
Copy after login

Result: (Error message: Note that abc is already a constant.)

abc
Notice: Constant abc already defined in C:\wamp\www\Untitled-1.php on line 12
abc
Copy after login
<?php
$abc=false;
echo $abc.&#39;<br>&#39;;//空白
$abc=&#39;我是变量&#39;;
ecoh $abc;
?>
Copy after login

Use directly $ defines all variables.

Relevant learning recommendations: php graphic tutorial

The above is the detailed content of Can php delete constants?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template