<?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>magic constants in php - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/magic-constants-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/magic-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>magic constants in php - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/magic-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>
		<item>
		<title>What are Magic Constants in PHP ?</title>
		<link>https://www.wikitechy.com/interview-questions/php/what-are-magic-constants-in-php/</link>
					<comments>https://www.wikitechy.com/interview-questions/php/what-are-magic-constants-in-php/#respond</comments>
		
		<dc:creator><![CDATA[webmaster]]></dc:creator>
		<pubDate>Mon, 01 Aug 2022 09:09:07 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[default constant in php]]></category>
		<category><![CDATA[define and constant in php]]></category>
		<category><![CDATA[magic constant]]></category>
		<category><![CDATA[magic constant c++]]></category>
		<category><![CDATA[magic constants in php]]></category>
		<category><![CDATA[php __class__]]></category>
		<category><![CDATA[php __file__]]></category>
		<category><![CDATA[undefined constant php]]></category>
		<category><![CDATA[what is a constant in php]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=4535</guid>

					<description><![CDATA[In PHP magic constants are the predefined constants which is used on the basis of their use. Constants are created by various extensions and there are nine magic constants in the PHP and all of the constant resolved at the compile-time, not like the regular constant which is resolved at run time. In this there [&#8230;]]]></description>
										<content:encoded><![CDATA[<ul>
<li style="text-align: justify;">In PHP magic constants are the predefined constants which is used on the basis of their use.</li>
<li style="text-align: justify;">Constants are created by various extensions and there are nine magic constants in the PHP and all of the constant resolved at the compile-time, not like the regular constant which is resolved at run time.</li>
<li style="text-align: justify;">In this there are eight magic constants which start and end with double underscores (__), they are.
<ul>
<li>__line__</li>
<li>__file__</li>
<li>__dir__</li>
<li>__function__</li>
<li>__class__</li>
<li>__method__</li>
<li>__namespace__</li>
<li>__trait__</li>
</ul>
</li>
</ul>
<h2 id="__line__" style="text-align: justify;">__line__</h2>
<ul style="text-align: justify;">
<li>This type of magic constant returns the current line number of the file.</li>
<li>In our program file if we use this magic constant somewhere then this constant will display the line number during compile time.</li>
</ul>
<h3 id="syntax" style="text-align: justify;"><strong>Syntax</strong></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">         __line__</code></pre> </div>
<h2 id="__file__" style="text-align: justify;">__file__</h2>
<ul style="text-align: justify;">
<li>This type of magic constant return the full path of the executed file with the name of the file.</li>
</ul>
<h3 id="syntax-2" style="text-align: justify;"><strong>Syntax</strong></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">         __file__</code></pre> </div>
<h2 id="__dir__" style="text-align: justify;">__dir__</h2>
<ul style="text-align: justify;">
<li>This type of magic constant returns the directory of the executed file.</li>
</ul>
<h3 id="syntax-3" style="text-align: justify;"><strong>Syntax</strong></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">          __dir__</code></pre> </div>
<h2 id="__function__"><span lang="EN-US" style="font-size: 16pt; font-family: 'Segoe UI', sans-serif; color: #000000; letter-spacing: 0.1pt;">__function__</span></h2>
<ul style="text-align: justify;">
<li>This type of magic constant returns the name of the function where it is included.</li>
</ul>
<h3 id="syntax-4" style="text-align: justify;"><strong>Syntax</strong></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">         __function__</code></pre> </div>
<h2 id="__class__"><span lang="EN-US" style="font-size: 16pt; font-family: 'Segoe UI', sans-serif; color: #000000; letter-spacing: 0.1pt;">__class__</span></h2>
<ul style="text-align: justify;">
<li>This type of magic constant returns the name of the class where it is included.</li>
</ul>
<h3 id="syntax-5" style="text-align: justify;"><strong>Syntax</strong></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">__class__</code></pre> </div>
<h2 id="__method__" style="text-align: justify;">__method__</h2>
<ul style="text-align: justify;">
<li>This type of magic constant returns the method name where it is included.</li>
</ul>
<h3 id="syntax-6" style="text-align: justify;"><strong>Syntax</strong></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">       __method__</code></pre> </div>
<h2 id="__namespace__" style="text-align: justify;">__namespace__</h2>
<p style="text-align: justify;">This type of magic constant returns the current namespace where it is included.</p>
<h3 id="syntax-7" style="text-align: justify;"><strong>Syntax</strong></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">       __namespace__</code></pre> </div>
<h2 id="__trait__" style="text-align: justify;">__trait__</h2>
<ul style="text-align: justify;">
<li>This type of magic constant returns the trait name where it is included.</li>
</ul>
<h3 id="syntax-8" style="text-align: justify;"><strong>Syntax</strong></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">  __trait__</code></pre> </div>
<p style="text-align: justify;">
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/php/what-are-magic-constants-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
