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 7769595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:11:55+00:00 2026-06-01T16:11:55+00:00

I have a simple question, which should hopefully have a quick answer. The code

  • 0

I have a simple question, which should hopefully have a quick answer. The code I have written makes heavy use of namespaces (I use fully qualified names everywhere); however, a piece of code (a calendar / date picker control, not written by myself) needs to be included. When I attempt to create the control, it assumes the current namespace (GUI), resulting in this error: “PHP Fatal error: Class ‘GUI\tc_calendar’ not found in C:\inetpub\wwwroot\Calico\calico_classes_v2.php on line 1852”. Now, the calendar control itself (and it’s underlying class file) does not make use of namespaces, and I am a little worried about attempting to modify it (an earlier attempt did not go well).

How can I import / include a control, that is not contained within a namespace, into the rest of my code, that does? Does PHP have something like “Import class calendar from file AS \Calendar\Calendar”?

Edit:
For additional information: I have a class, called “tc_calendar”, contained in a file called “tc_calendar.php”. It is not part of any namespace.

In a separate file, I have several classes (Bitmap, CompositeCalendar, EventEditor, TimeExtractor), all contained within their appropriate namespaces (GUI, Data, Extract, etc.).

In one of those classes, CompositeCalendar, contained within the GUI namespace, I am trying to create an instance of a tc_calendar. However, PHP is throwing an error (above). tc_calendar is not a part of any namspace (and definitely not a part of the GUI namespace, which PHP is just assuming, because it can’t seem to find it), and I need help creating an instance of it.

tldr; $newcontrol = new tc_calendar() doesn’t work; PHP tries to guess the namespace for it (because one isn’t specified, because tc_calendar isn’t a part of any namespace), comes up with \GUI\tc_calendar (obviously wrong). How do I access a class, not contained within a namespace, from inside a namespace?

  • 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-06-01T16:11:56+00:00Added an answer on June 1, 2026 at 4:11 pm

    Do you mean something like this:

    namespace GUI;
    
    use \tc_calendar as Calendar;
    
    $myCalendar = new Calendar();
    

    The as Calendar is optional. You could aswell keep it with the original name tc_calendar if you ommit the as Calendar.

    Update

    To put it in shape of the comment:

    namespace {
        class tc_calendar {} 
    }
    namespace GUI {
        use \tc_calendar;
    
        class CompositeCalendar { 
            private function blah() { 
                 $control = new tc_calendar();   
                 $control->stuff(); 
            } 
        }
    }
    

    I wouldn’t copy paste external libraries into he same file though. It bad practise. It is better to keep them in another file and then include them and have the following:

    namespace GUI;
    
    use \tc_calendar;
    
    require_once 'tc_calendar.php';
    
    class CompositeCalendar { 
            private function blah() { 
                 $control = new tc_calendar();   
                 $control->stuff(); 
            } 
    }
    

    Or combine my 3 snippets to have it any other form you like.

    Also I would suggest to extend the calendar if you are just building calendar class based on the the tc_calendar:

    namespace GUI;
    
    use \tc_calendar;
    
    require_once 'tc_calendar.php';
    
    class CompositeCalendar extends tc_calendar { 
            private function blah() {  
                 $this->stuff(); 
            } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question which I can't seem to find an answer of: I have two
Simple question which I can't find the answer to: How can I use JavaScript
I have a simple security question which I just can't find the answer to.
Simple question for which I think I have an answer but I am looking
I have a pretty simple question which perhaps someone familiar with Server/Client design &
I have a very simple question for which I can't seem to find an
A fairly simple question for which I have a guess, but I can't find
I have a simple question and wish to hear others' experiences regarding which is
A simple question. I have an ASP.NET web application which contains several assemblies and
simple question... Given I have an ASP.NET site, which uses a [custom] RoleProvider, Is

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.