<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>how to use constants in php - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/how-to-use-constants-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/how-to-use-constants-in-php/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Wed, 03 Aug 2022 12:03:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>how to use constants in php - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/how-to-use-constants-in-php/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What are the ways to define a constant in PHP ?</title>
		<link>https://www.wikitechy.com/interview-questions/php/what-are-the-ways-to-define-a-constant-in-php/</link>
					<comments>https://www.wikitechy.com/interview-questions/php/what-are-the-ways-to-define-a-constant-in-php/#respond</comments>
		
		<dc:creator><![CDATA[webmaster]]></dc:creator>
		<pubDate>Wed, 03 Aug 2022 12:03:36 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[how to define constants in php]]></category>
		<category><![CDATA[how to use constants in php]]></category>
		<category><![CDATA[magic constants in php]]></category>
		<category><![CDATA[php constant case-insensitive]]></category>
		<category><![CDATA[php constants]]></category>
		<category><![CDATA[php constants array]]></category>
		<category><![CDATA[php constants in class]]></category>
		<category><![CDATA[php constants types]]></category>
		<category><![CDATA[php protected static const]]></category>
		<category><![CDATA[php unset constant]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=4564</guid>

					<description><![CDATA[PHP constants are identifier or name that can&#8217;t be changed during the execution of the script except for magic constants, which are not really constants. Constants can never be undefined or changed, they are similar to the variable except once defined. PHP constants follow the same PHP variable rules and it remains constant across the [&#8230;]]]></description>
										<content:encoded><![CDATA[<ul>
<li><a href="https://www.wikitechy.com/php/php-constants">PHP constants</a> are identifier or name that can&#8217;t be changed during the execution of the script except for magic constants, which are not really constants.</li>
<li>Constants can never be undefined or changed, they are similar to the variable except once defined.</li>
<li>PHP constants follow the same PHP variable rules and it remains constant across the entire program.</li>
<li>Conventionally, in uppercase letters PHP constants should be defined and it can be started with an underscore or letter only.</li>
<li>PHP constants consists of two types, they are:
<ul>
<li>Using define () function</li>
<li>Using const keyword</li>
</ul>
</li>
</ul>
<h2 id="using-define-function">Using define () function</h2>
<ul>
<li>In PHP use the define () function to create a constant and it defines constant at run time.</li>
<li>In this function name specifies the constant name, value specifies the constant value and case-insensitive specifies whether a constant is case-insensitive.</li>
<li>By default, if value is false it means it is case sensitive.</li>
</ul>
<h3 id="sample-code">Sample Code</h3>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-php code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-php code-embed-code">&lt;?php    <br/>define(&quot;MESSAGE&quot;,&quot;Welcome to Wikitechy&quot;,true);//not case sensitive    <br/>echo MESSAGE, &quot;&lt;/br&gt;&quot;;    <br/>echo message;    <br/>?&gt;    </code></pre> </div>
<h3 id="output">Output</h3>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4565" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function.png" alt="" width="1229" height="309" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function.png 1229w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function-300x75.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function-1024x257.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function-768x193.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function-390x98.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function-820x206.png 820w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/define-function-1180x297.png 1180w" sizes="(max-width: 1229px) 100vw, 1229px" /></p>
<h2 id="using-const-keyword">Using const Keyword</h2>
<ul>
<li>PHP introduces a const keyword to create a constant and it defines constants at compile time.</li>
<li>It constructs a language, not a function.</li>
<li>The constant defined using const keyword are <strong>case-sensitive</strong>.</li>
</ul>
<h3 id="sample-code-2">Sample Code</h3>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-php code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-php code-embed-code">&lt;?php      <br/>    define(&quot;MSG&quot;, &quot;Wikitechy&quot;);  <br/>    echo MSG, &quot;&lt;/br&gt;&quot;;  <br/>    echo constant(&quot;MSG&quot;);  <br/>    //both are similar  <br/>?&gt;  </code></pre> </div>
<h3 id="output-2">Output</h3>
<p><img decoding="async" class="alignnone size-full wp-image-4566 aligncenter" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword.png" alt="" width="1230" height="290" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword.png 1230w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword-300x71.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword-1024x241.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword-768x181.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword-390x92.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword-820x193.png 820w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/const-keyword-1180x278.png 1180w" sizes="(max-width: 1230px) 100vw, 1230px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/php/what-are-the-ways-to-define-a-constant-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
