{"id":18823,"date":"2015-12-12T02:01:50","date_gmt":"2015-12-11T16:01:50","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=18823"},"modified":"2015-12-12T07:17:19","modified_gmt":"2015-12-11T21:17:19","slug":"php-namespace-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-namespace-primer-tutorial\/","title":{"rendered":"PHP Namespace Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mynamespace.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Namespace Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_ns.jpg\" title=\"PHP Namespace Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">PHP Namespace Primer Tutorial<\/p><\/div>\n<p>The concept of a <i>namespace<\/i> exists in several computer languages, but of those, today we start on a discussion of its <a target=_blank title='Encapsulation information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Encapsulation_%28computer_programming%29'><i>encapsulation<\/i><\/a> role with PHP.<\/p>\n<p>A great source of information for information about PHP namespaces is this <a target=_blank title='PHP namespaces information' href='http:\/\/php.net\/manual\/en\/language.namespaces.rationale.php'>great link<\/a> from the &#8220;home of PHP&#8221; &#8230; we always find.<\/p>\n<p>Being as you can do without &#8220;namespaces&#8221; programming with PHP, let&#8217;s hone in on a couple of reasons you may want to make use of them (even so), taken from that aforesaid mentioned link &#8230;<\/p>\n<blockquote>\n<ol>\n<li>Name collisions between code you create, and internal PHP classes\/functions\/constants or third-party classes\/functions\/constants.<\/li>\n<li>Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code. <\/li>\n<\/ol>\n<\/blockquote>\n<p>From that same link we modify some of its code to show you some concepts regarding this, having a named &#8220;namespace&#8221; section code establish its own &#8220;strlen($strvar)&#8221; function (negating the &#8220;\\strlen($strvar)&#8221; call result).<\/p>\n<p>We have this named &#8220;namespace&#8221; code set up its own <i>MYCONST<\/i> constant, and you can see how this works as well.<\/p>\n<p>We don&#8217;t use it here, but also, in relation to named &#8220;namespace&#8221; code, you will want to research from the &#8220;home of PHP&#8221; the aliasing use of the PHP <a target=_blank title='PHP use keyword information' href='http:\/\/php.net\/manual\/en\/language.namespaces.importing.php'><i>use<\/i><\/a> keyword.<\/p>\n<p>For today&#8217;s PHP code <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mynamespace.php\" title='Click picture'>live run<\/a> we have PHP code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mynamespace.php_GETME\" title='mynamespace.php'>mynamespace.php<\/a> for your perusal.  We hope it helps.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d18823' onclick='var dv=document.getElementById(\"d18823\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/php\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d18823' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The concept of a namespace exists in several computer languages, but of those, today we start on a discussion of its encapsulation role with PHP. A great source of information for information about PHP namespaces is this great link from &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-namespace-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,28,37],"tags":[210,1760,1759,471,1758,932,997,1319],"class_list":["post-18823","post","type-post","status-publish","format-standard","hentry","category-elearning","category-oop","category-tutorials","tag-class","tag-constant","tag-encapsulation","tag-function","tag-namespace","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/18823"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=18823"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/18823\/revisions"}],"predecessor-version":[{"id":18832,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/18823\/revisions\/18832"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=18823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=18823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=18823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}