I'm still having problems with PHP5 namespaces.
I have a namespace called Project , and I'm trying to access a class called registry inside this Project namespace that has a Library namespace, so at the top of the file that is Project namespace I use this line use Library\Registry;
registry class is inside the namespace library
This should work, but it is not, instead, the only way to access my registry class inside this Project namespace is to use this
$this->registry = new \Library\Registry;
I want to use this instead ...
$this->registry = new Registry;
This is the reason for using
use Library\Registry;
at the top of the Project namespace file
Below I have 3 small sample scripts in a folder structure like this. Library/registry.class.php class in my library folder
Controller/controller.class.php and class in my controller directory
Controller/testing.php test file to run the script.
E: \ Library \ Registry.class.php file
<?php namespace Library { class Registry { function __construct() { echo 'Registry.class.php Constructor was ran'; } } } ?>
File E: \ Controller \ Controller.class.php
<?php use Library\Registry; namespace Project { class Controller { public $registry; function __construct() { include('E:\Library\Registry.class.php');
File E: \ Controller \ testing.php
<?php use Project\Controller; include('testcontroller.php'); $controller = new Controller(); $controller->show(); ?>
I get this error ...
Fatal error: Class 'Project\Registry' not found in PATH to file
if i don't use it below in controller.class.php file
$this->registry = new \MyLibrary\Registry;
Because in this file at the top, I use Library\Registry; I must have access to it like this ...
$this->registry = new Registry;
Please help me get it, where can I use it like that