Home  >  Article  >  Backend Development  >  Can php delete constants?

Can php delete constants?

coldplay.xixi
coldplay.xixiOriginal
2020-08-05 10:20:163576browse

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);
?>

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

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;
?>

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
<?php
$abc=false;
echo $abc.&#39;<br>&#39;;//空白
$abc=&#39;我是变量&#39;;
ecoh $abc;
?>

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!

Statement:
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