Reputation: 27689
Im trying to figure out how namespaces works in PHP, but havent really been lucky
Hope somebody could tell me what Im doing wrong here :)
require_once 'Vatcode.php';
$Vatcode = new \resource\Vatcode();
namespace resource;
require_once Ini::get('path/class').'/Resource.php';
class Vatcode extends Resource {
public function __construct(){
echo 'works!';
}
}
namespace resource;
class Resource {
}
Fatal error: Class 'resource\Ini' not found in Vatcode.php
Upvotes: 0
Views: 1017
Reputation: 3713
it's just a problem of namespace.
Your class Vatcode is in namesapce ressource. If, in the file of VatCode declaration you use nameofclas::...
or new nameofclass()
it will try to get the class in namespace ressource.
If you want to use the class Ini inside your document you have two solutions :
first give the full qualified name :
require \namespace\of\ini\Ini::get('path/class').'/Resource.php';
second using the "use" keyworld before using the get method :
use \namespace\of\ini\Ini;
require_once Ini::get('path/class').'/Resource.php';
In any case, if Ini is in "no namespace" (global namespace is the accurate word) you just has to use the solutions I gave you but only with \Ini
instead of \namespace\of\ini\Ini
Upvotes: 3