I am working with php under xampp.
In my C:\xampp\htdocs\AppLib1\lib1.php
<?php
// application library 1 i.e. lib1.php
namespace AppLib1;
const MYCONST = 'AppLib1MYCONST';
function MyFunction() {
return __FUNCTION__;
}
class MyClass {
static function WhoAmI() {
return __METHOD__;
}
}
?>
and in my C:\xampp\htdocs\myapp.php
<?php
//myapp.php
header('Content-type: text/plain');
include_once ('lib1.php');
echo AppLib1MYCONST . "n";
echo AppLib1MyFunction() . "n";
echo AppLib1MyClass::WhoAmI() . "n";
?>
now when i am running myapp.php locally, I am getting Fatal Error
Warning: require_once(lib1.php): failed to open stream: No such file or directory in C:\xampp\htdocs\myapp.php on line 3
Fatal error: require_once(): Failed opening required 'lib1.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\myapp.php on line 3
Can some explain me how to use function, class, constant from lib1.php
output should be: AppLib1MYCONST AppLib1MyFunction AppLib1MyClass::WhoAmI
I Know Name collision problems can be solved with namespaces.