This PHP program demonstrates how to use predefined constants to debug a PHP program.
<?php
namespace NTestNamespace;
$fnPrintDiagonostics = function() {
echo "Directory: ".__DIR__.
"<br />File: ".__FILE__.
"<br />Line: ".__LINE__.
"<br />Namespace: ".__NAMESPACE__.
"<br />Method: ".__METHOD__.
"<br />Class: ".__CLASS__.
"<br />Trait: ".__TRAIT__."<hr />";
};
// Call the anonymous function
echo "<h3>Calling an anonymous function</h3>";
$fnPrintDiagonostics();
function fnTestFunction() {
echo "Directory: ".__DIR__.
"<br />File: ".__FILE__.
"<br />Line: ".__LINE__.
"<br />Namespace: ".__NAMESPACE__.
"<br />Method: ".__METHOD__.
"<br />Class: ".__CLASS__.
"<br />Trait: ".__TRAIT__."<hr />";
};
// Call a regular function or method
echo "<h3>Calling fnTestFunction()</h3>";
fnTestFunction();
// A very simple trait
trait TTestTrait {
public function fnTraitFunction() {
echo "Directory: ".__DIR__.
"<br />File: ".__FILE__.
"<br />Line: ".__LINE__.
"<br />Namespace: ".__NAMESPACE__.
"<br />Method: ".__METHOD__.
"<br />Class: ".__CLASS__.
"<br />Trait: ".__TRAIT__."<hr />";
}
}
// A simple class
class CTestClass {
use TTestTrait;
public function __construct() {
echo "<h3>Calling fnTestFunction() within the constructor</h3>";
fnTestFunction();
echo "<h3>Calling the Constructor</h3>";
echo "Directory: ".__DIR__.
"<br />File: ".__FILE__.
"<br />Line: ".__LINE__.
"<br />Namespace: ".__NAMESPACE__.
"<br />Method: ".__METHOD__.
"<br />Class: ".__CLASS__.
"<br />Trait: ".__TRAIT__."<hr />";
}
}
$qObject = new CTestClass();
echo "<h3>Calling fnTraitFunction()</h3>";
$qObject->fnTraitFunction();
?>
© 20072025 XoaX.net LLC. All rights reserved.