{"id":169,"date":"2012-01-31T20:09:21","date_gmt":"2012-01-31T20:09:21","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=169"},"modified":"2022-02-17T07:14:05","modified_gmt":"2022-02-17T07:14:05","slug":"constants","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/memory\/constants","title":{"rendered":"Constants"},"content":{"rendered":"<h4>Constants<\/h4>\n<pre><code>  define (\"MY_ROOT_PATH\", \"\/usr\/local\/httpdocs\/\");<\/code><\/pre>\n<p>Then to use<\/p>\n<pre><code>  $PathToUse = MY_ROOT_PATH;<\/code><\/pre>\n<h4>PHP Magic Constants<\/h4>\n<p>__LINE__<\/p>\n<p style=\"padding-left: 30px;\">The current line number of the file.<\/p>\n<p>__FILE__<\/p>\n<p style=\"padding-left: 30px;\">The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.<\/p>\n<p>__DIR__<\/p>\n<p style=\"padding-left: 30px;\">The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)<\/p>\n<p>__FUNCTION__<\/p>\n<p style=\"padding-left: 30px;\">The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.<\/p>\n<p>__CLASS__<\/p>\n<p style=\"padding-left: 30px;\">The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. The class name includes the namespace it was declared in (e.g. Foo\\Bar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in.<\/p>\n<p>__TRAIT__<\/p>\n<p style=\"padding-left: 30px;\">The trait name. (Added in PHP 5.4.0) As of PHP 5.4 this constant returns the trait as it was declared (case-sensitive). The trait name includes the namespace it was declared in (e.g. Foo\\Bar).<\/p>\n<p>__METHOD__<\/p>\n<p style=\"padding-left: 30px;\">The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).<\/p>\n<p>__NAMESPACE__<\/p>\n<p style=\"padding-left: 30px;\">The name of the current namespace (case-sensitive). This constant is defined in compile-time (Added in PHP 5.3.0).<\/p>\n<p><a href=\"http:\/\/php.net\/manual\/en\/language.constants.predefined.php\" target=\"_blank\" rel=\"noopener noreferrer\">Full Descriptions<\/a><\/p>\n<h4>Useful Debugging Examples<\/h4>\n<pre><code>\r\n  echo \"Line: \" . __LINE__ . \" of file: \" . __FILE__;\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Constants define (&#8220;MY_ROOT_PATH&#8221;, &#8220;\/usr\/local\/httpdocs\/&#8221;); Then to use $PathToUse = MY_ROOT_PATH; PHP Magic Constants __LINE__ The current line number of the file. __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-169","post","type-post","status-publish","format-standard","hentry","category-memory"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=169"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":3231,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/169\/revisions\/3231"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}