Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:43:14+00:00 2026-05-27T18:43:14+00:00

I am still having trouble with PHP5 Namespaces. I have a namespace called Project

  • 0

I am still having trouble with PHP5 Namespaces.

I have a namespace called Project and I am trying to access a class called registry inside of this Project namespace that has a namespace of Library so at the top of the file that is a Project namespace I use this line use Library\Registry;

Registry class is inside the Library Namespace

This should work but it doesn’t, 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 be able to use this instead…

$this->registry = new Registry;

That was the whole reason of using

use Library\Registry;

at the top of the Project namespace file


Below I have 3 small example scripts in a folder structure like this.
Library/registry.class.php a class in my Library folder
Controller/controller.class.php and class in my Controller directory
Controller/testing.php a 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';
        }
    }
}
?>

E:\Controller\Controller.class.php file

<?php
use Library\Registry;

namespace Project
{
    class Controller
    {
        public $registry;

        function __construct()
        {
            include('E:\Library\Registry.class.php');

            // This is where my trouble is
            // to make it work currently I have to use
            //  $this->registry = new /Library/Registry;
            // But I want to be able to use it like below and that is why
            // I have the `use Library\Registry;` at the top
            $this->registry = new Registry;
        }

        function show()
        {
            $this->registry;
            echo '<br>Registry was ran inside testcontroller.php<br>';
        }
    }
}
?>

E:\Controller\testing.php file

<?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

unless I use this below on the controller.class.php file

$this->registry = new \MyLibrary\Registry;

Because in that file at the top I have use Library\Registry; I should be able to access it like this…

$this->registry = new Registry;

Please help me get it where I can use it like that instead

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:43:14+00:00Added an answer on May 27, 2026 at 6:43 pm
    use Library\Registry;
    
    namespace Project
    {
    

    I believe that’s the wrong way round: you’re useing Library\Registry in the global namespace, and then opening the Project namespace.

    Put the use statement inside the namespace you want to import it into.

    namespace Project
    {
        use Library\Registry;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still having trouble with this language. Ok, let's say I have two objects. The
I have read a couple of articles but im still having trouble understanding this.
I know this has been asked a thousand times but I'm still having trouble
I know a lot of people have posted for this, but I'm still having
I have been through the sed one liners but am still having trouble with
This is an age-old question, but I'm still having trouble with it. You see,
Still having trouble can you please help? This needs to be written in Visual
I was looking at this link , but was still having trouble creating my
I am still having trouble understanding what interfaces are good for. I read a
I am getting comfortable writing regular queries in SPARQL, but I'm still having trouble

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.