<?php
namespace my\name; // see "Defining Namespaces" section
error_reporting(E_ALL);
ini_set("display_errors", 1);

function exception_error_handler($errno, $errstr, $errfile, $errline ) {
    // Ideas via ... http://php.net/manual/en/function.set-error-handler.php ... thanks
    if (error_reporting() === 0) {
        return;
    }
    
    if (strpos($errstr, "constant(): Couldn't find constant") !== false) {
      $lines = file("mynamespace.php");
      echo "<br><p style='background-color: orange;'>It's a fine time to leave me loose wheel (ie. the Linux group name) ... but we're going to let the Warning ... <i>" . $errstr . "</i> ... that resulted from ...<br><br><b><i>" . str_replace("<br>", "&lt;br&gt;", $lines[-1 + $errline]) . "</i></b>   /" . "/ at line " . $errline . "<br><br> ... through, okay?!</p><br>";
    } else {
      throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
}

$oerrh = set_error_handler("my\\name\\exception_error_handler");

function catchException($e) {
    // Do some stuff ... via ... http://php.net/manual/en/function.set-exception-handler.php ... thanks
    try {
        // ... normal exception stuff goes here
        print $undefined; // This is the underlying problem
    } catch (Exception $e) {
        print get_class($e)." thrown within the exception handler. Message: ".$e->getMessage()." on line ".$e->getLine();
    }
}

$oeh = set_exception_handler('my\name\catchException');

class MyClass {}
function myfunction() {}
function strlen($inc) { return (0 - \strlen($inc)); }
const MYCONST = 1;

echo "<!doctype html><html><head><title>Talking about PHP Namespace</title></head><body style='background-color:yellow;'><h1 align='center' style='background-color:pink;'>Talking about PHP Namespace</h1><br><br><div align='center'>";

$a = new MyClass;
$c = new \my\name\MyClass; // see "Global Space" section

echo "\strlen('hello') = " . \strlen('hello') . ' <br>';

echo "namespace\strlen('hello') = " . namespace\strlen('hello') . ' <br>';

echo "__NAMESPACE__ . '\strlen(\"hello\")' equates to " . __NAMESPACE__ . "\strlen(\"hello\") = " . strlen("hello") . ' <br><br><br>';

$a = \strlen('hello'); // see "Using namespaces: fallback to global
                   // function/constant" section

//echo "\strlen('hello') = " . $a . ' <br>';

$d = namespace\MYCONST; // see "namespace operator and __NAMESPACE__
                        // constant" section
                        
echo "namespace\MYCONST = '" . constant($d) . "' <br>"; 
                        
$d = __NAMESPACE__ . '\MYCONST';
echo "__NAMESPACE__ . '\MYCONST' equates to " . __NAMESPACE__ . "\MYCONST = " . constant($d) . ' <br>'; // see "Namespaces and dynamic language features" section


echo "</div></body></html>";

?>

