{"id":18833,"date":"2015-12-13T02:01:00","date_gmt":"2015-12-12T16:01:00","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=18833"},"modified":"2015-12-13T20:12:30","modified_gmt":"2015-12-13T10:12:30","slug":"php-namespace-error-handling-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-namespace-error-handling-tutorial\/","title":{"rendered":"PHP Namespace Error Handling 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 Error Handling Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php-ns.jpg\" title=\"PHP Namespace Error Handling Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">PHP Namespace Error Handling Tutorial<\/p><\/div>\n<p>Do <i>namespaces<\/i> deserve the status of <a target=_blank title='Onions of the 4th dimension' style='text-decoration:none;' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/?s=onion'>&#8220;onion shell&#8221;<\/a>?  We think <i>yes<\/i> &#8230; and we think so because their usage affects Error Handling code arrangements in PHP, so we need to talk more about <i>namespaces<\/i>, continuing on from yesterday&#8217;s <a title='PHP Namespace Primer Tutorial' href='#pnpt'>PHP Namespace Primer Tutorial<\/a> as shown below.<\/p>\n<p>Maybe you noticed, or maybe you didn&#8217;t, that yesterday&#8217;s live run caused an error, which yesterday&#8217;s code would have thrown at the web server it was running at &#8230; ie. the web server for domain www.rjmprogramming.com.au &#8230; and said words to the affect &#8220;<a target=_blank title='Throwable information' style='text-decoration:none;' href='http:\/\/php.net\/manual\/en\/class.throwable.php'>throw<\/a> me&#8221; &#8230; and less likely &#8230; &#8220;see if I care&#8221;.<\/p>\n<p>But you can, as you&#8217;d expect with any mature programming language, intervene, and have the errors flow through your own code before they are, perhaps, or maybe not, (still) passed onto the web server software for processing &#8230; where, often, depending on the PHP ini file settings for your Apache web server, will stop the webpage on a critical error.<\/p>\n<p>So PHP sees two concepts for error checking &#8230;<\/p>\n<ol>\n<li>an exception &#8230; more your I\/O type of problem, usually<\/li>\n<li>an error &#8230; less your I\/O type of problem, usually<\/li>\n<\/ol>\n<p> &#8230; and PHP has set aside two separate categories of error handling calling ideas to cater for each, respectively (to above) &#8230;<\/p>\n<ol>\n<li><a target=_blank title=PHP set_exception_handler information' href='http:\/\/php.net\/manual\/en\/function.set-exception-handler.php'>set_exception_handler(  callable $error_handler [, int $error_types = E_ALL | E_STRICT ] )<\/a> method<\/li>\n<li><a target=_blank title=PHP set_error_handler information' href='http:\/\/php.net\/manual\/en\/function.set-error-handler.php'>set_error_handler(  callable $error_handler [, int $error_types = E_ALL | E_STRICT ] )<\/a> method<\/li>\n<\/ol>\n<p> &#8230; and our actual problem yesterday was of the <i>set_error_handler()<\/i> variety &#8230; was involving the use a non-defined constant &#8230; nothing to do with I\/O there <strike>man<\/strike> person.<\/p>\n<p>Regarding named <i>namespaces<\/i> that <i>callable $error_handler<\/i> error handling function needs to be qualified by the nomenclature of the named namespace &#8230; as you will see with the PHP programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mynamespace.php-GETME\" title='mynamespace.php'>mynamespace.php<\/a> (changed from yesterday, regarding error handling, <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/mynamespace.php-GETME\" title='mynamespace.php'>this way<\/a>) and with a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mynamespace.php\" title='mynamespace.php'>live run<\/a> link here.<\/p>\n<p>Getting the feel of an &#8220;onion shell <a target=_blank title='Onions of the 4th dimension' style='text-decoration:none;' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/?s=onion'><font size=1>of the 4th dimension<\/font><\/a> <font size=3 color=red>and beyond<\/font>&#8221; today?<\/p>\n<hr>\n<p id='pnpt'>Previous relevant <a target=_blank title='PHP Namespace Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/php-namespace-primer-tutorial\/'>PHP Namespace Primer Tutorial<\/a> is shown below.<\/p>\n<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<hr>\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='#d18833' onclick='var dv=document.getElementById(\"d18833\"); 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='d18833' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Do namespaces deserve the status of &#8220;onion shell&#8221;? We think yes &#8230; and we think so because their usage affects Error Handling code arrangements in PHP, so we need to talk more about namespaces, continuing on from yesterday&#8217;s PHP Namespace &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-namespace-error-handling-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,37],"tags":[210,1760,1759,393,471,1758,932,997,1319],"class_list":["post-18833","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-class","tag-constant","tag-encapsulation","tag-error-handling","tag-function","tag-namespace","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/18833"}],"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=18833"}],"version-history":[{"count":12,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/18833\/revisions"}],"predecessor-version":[{"id":18859,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/18833\/revisions\/18859"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=18833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=18833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=18833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}