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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:40:52+00:00 2026-06-03T21:40:52+00:00

I have a Problem developing in PHP. First I have to say that I’m

  • 0

I have a Problem developing in PHP. First I have to say that I’m not the experienced PHP developer on this Planet.

My Code/Problem is as followed:

In file Controllers\TestController.php:

  <?php
  namespace My\Test\Controllers;

  class TestController
  {
     public function HelloTest()
     {
          echo 'Hello!';
     } 
  }
?>

When I want to include this class in another php file like this

File Models\TestModel.php:

<?php
     namespace My\Test\Models;
     use My\Test\Controllers;         

     class TestModel
     {
       public function TestModelFunction()
       {
         $control = new TestClass();
         $control->HelloTest();
       }
     } 
?>

File index.php_

 <?php
      use My\Test\Models;

      $model = new TestModel();
      $model->TestModelFunction();
  ?>

That just won’t work… I’ll always get the following error:

Class ‘TestModel’ not found!

When I now add:

include_once 'Models/TestModel.php' in index.php
AND
include_once '..Controllers/TestController.php' in TestModel.php
then it works…

Folder Structure:

Project
|-Models
|  TestModel.php
|-Controllers
|  TestController.php
|index.php

But do I really have to specify every Time where the files are?

  • 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-03T21:40:52+00:00Added an answer on June 3, 2026 at 9:40 pm

    Yes you will always have to include the files that define your classes.

    The namespace is just a way to package your classes together, not a way to automatically include PHP files.

    If your are looking for a way to automatically include PHP files when needed, have a look on autoload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently developing a PHP framework and have ran into my first problem. I need
I am developing a joomla extension and in default.php file i have this code:
I have this problem and it's drivin' me nuts! So I am developing my
I'm hoping people have some ideas to help solve this problem. I am developing
I have run into an interesting problem. I am currently developing php page and
i'm developing a php extension (not my first one), but today i stumble upon
I have this ajax web application I am developing that essentially calls the google
I'm developing a PHP-MySQL app that enables registered users to enter text comments. Problem
I have to work with another team that is developing in php, when I'm
i have a problem i am developing an asp.net mvc project. Website is in

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.