<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4535,"date":"2022-08-01T09:09:07","date_gmt":"2022-08-01T09:09:07","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4535"},"modified":"2022-08-01T09:30:59","modified_gmt":"2022-08-01T09:30:59","slug":"what-are-magic-constants-in-php","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/","title":{"rendered":"What are Magic Constants in PHP ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">In PHP magic constants are the predefined constants which is used on the basis of their use.<\/li>\n<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>\n<li style=\"text-align: justify;\">In this there are eight magic constants which start and end with double underscores (__), they are.\n<ul>\n<li>__line__<\/li>\n<li>__file__<\/li>\n<li>__dir__<\/li>\n<li>__function__<\/li>\n<li>__class__<\/li>\n<li>__method__<\/li>\n<li>__namespace__<\/li>\n<li>__trait__<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"__line__\" style=\"text-align: justify;\">__line__<\/h2>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant returns the current line number of the file.<\/li>\n<li>In our program file if we use this magic constant somewhere then this constant will display the line number during compile time.<\/li>\n<\/ul>\n<h3 id=\"syntax\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<h2 id=\"__file__\" style=\"text-align: justify;\">__file__<\/h2>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant return the full path of the executed file with the name of the file.<\/li>\n<\/ul>\n<h3 id=\"syntax-2\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<h2 id=\"__dir__\" style=\"text-align: justify;\">__dir__<\/h2>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant returns the directory of the executed file.<\/li>\n<\/ul>\n<h3 id=\"syntax-3\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<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>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant returns the name of the function where it is included.<\/li>\n<\/ul>\n<h3 id=\"syntax-4\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<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>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant returns the name of the class where it is included.<\/li>\n<\/ul>\n<h3 id=\"syntax-5\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<h2 id=\"__method__\" style=\"text-align: justify;\">__method__<\/h2>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant returns the method name where it is included.<\/li>\n<\/ul>\n<h3 id=\"syntax-6\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<h2 id=\"__namespace__\" style=\"text-align: justify;\">__namespace__<\/h2>\n<p style=\"text-align: justify;\">This type of magic constant returns the current namespace where it is included.<\/p>\n<h3 id=\"syntax-7\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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>\n<h2 id=\"__trait__\" style=\"text-align: justify;\">__trait__<\/h2>\n<ul style=\"text-align: justify;\">\n<li>This type of magic constant returns the\u00a0trait name where it is included.<\/li>\n<\/ul>\n<h3 id=\"syntax-8\" style=\"text-align: justify;\"><strong>Syntax<\/strong><\/h3>\n<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\">\u00a0 __trait__<\/code><\/pre> <\/div>\n<p style=\"text-align: justify;\">\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[8182],"tags":[17670,17665,17667,17668,17664,17669,17666,17671,17663],"class_list":["post-4535","post","type-post","status-publish","format-standard","hentry","category-php","tag-default-constant-in-php","tag-define-and-constant-in-php","tag-magic-constant","tag-magic-constant-c","tag-magic-constants-in-php","tag-php-__class__","tag-php-__file__","tag-undefined-constant-php","tag-what-is-a-constant-in-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What are Magic Constants in PHP ? - PHP Magic Constants - Wikitechy<\/title>\n<meta name=\"description\" content=\"What are Magic Constants in PHP ? - In PHP magic constants are the predefined constants which is used on the basis of their use.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What are Magic Constants in PHP ? - PHP Magic Constants - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"What are Magic Constants in PHP ? - In PHP magic constants are the predefined constants which is used on the basis of their use.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-01T09:09:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-01T09:30:59+00:00\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/\",\"name\":\"What are Magic Constants in PHP ? - PHP Magic Constants - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"datePublished\":\"2022-08-01T09:09:07+00:00\",\"dateModified\":\"2022-08-01T09:30:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What are Magic Constants in PHP ? - In PHP magic constants are the predefined constants which is used on the basis of their use.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What are Magic Constants in PHP ? - PHP Magic Constants - Wikitechy","description":"What are Magic Constants in PHP ? - In PHP magic constants are the predefined constants which is used on the basis of their use.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/","og_locale":"en_US","og_type":"article","og_title":"What are Magic Constants in PHP ? - PHP Magic Constants - Wikitechy","og_description":"What are Magic Constants in PHP ? - In PHP magic constants are the predefined constants which is used on the basis of their use.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/","og_site_name":"Wikitechy","article_published_time":"2022-08-01T09:09:07+00:00","article_modified_time":"2022-08-01T09:30:59+00:00","author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/","name":"What are Magic Constants in PHP ? - PHP Magic Constants - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"datePublished":"2022-08-01T09:09:07+00:00","dateModified":"2022-08-01T09:30:59+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What are Magic Constants in PHP ? - In PHP magic constants are the predefined constants which is used on the basis of their use.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/php\/what-are-magic-constants-in-php\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4535"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4535\/revisions"}],"predecessor-version":[{"id":4538,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4535\/revisions\/4538"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}