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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:49:06+00:00 2026-06-18T12:49:06+00:00

A product in my company (& me too) was using PHP 5.2. I want

  • 0

A product in my company (& me too) was using PHP 5.2.

I want to switch to 5.4 so I’m doing some basic tests with 5.4 for the first time.

As per PSR 0, I followed the following folder structure for a simple test:

Projectfolder
   |
   + index.php
   |
   + lib
      |
      + vendor
          |
          +  mylib
               |
               + MyClass.php (Having namespace \mylib )

Here is our code, called MyClass.php:

namespace \mylib;
class MyClass {
    public $testA;
    public function MyClass(){
        $this->testA = "test entry";
    }
}

My problem is how to get an instance of MyClass in the index.php file?

Before Namespace, I could have done this:

include "lib/vendor/mylib/MyClass.php";
$myClass = new MyClass();
echo $myClass->testA;

Now with namespace, I try the following code:

<?PHP
use mylib\MyClass
$myClass = new MyClass();
echo $myClass->testA;

However, I get the following error:

Fatal error: Class ‘mylib\MyClass’ not found …

My problem is, how do I tell PHP to look namespace files in folder lib\vendor.

In Java, we generally define a classpath. Is there a similar setting in PHP?

As seen in some examples in namespace tutorial, I need to include all PHP files containing all classes to be used (10, 20, 50 any number). I guess that should not be the case or whole purpose of introducing namespace in PHP will be defeated.

  • 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-18T12:49:07+00:00Added an answer on June 18, 2026 at 12:49 pm

    even WITH namespaces you must include the files.
    Namespaces are for referencing those classes AFTER they are included.

    SO that you can

    include "lib/vendor/mylib/MyClass.php";
    use mylib;
    \mylib\myClass::myFunction();
    

    without new MyClass();

    see http://php.net/manual/en/language.namespaces.php for detailed example

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

Sidebar

Related Questions

My C++ application stores some common user data in %CSIDL_COMMON_APPDATA%\Company\Product . I want to
Our company publishes our software product's documentation using a custom-built content management system using
My company is switching from Subversion to Mercurial. We're using .NET for our product.
I recently joined a company which is using django to build their product. I'm
I have a two columns named Company & Project I want to select all
I need to write an SNMP agent on Windows for our company product. SnmpApi.lib
I am working on an installation program for one of my company's product. The
I'm attempting to use the QuickBooks API to sync up my company's product list
Our company has a product which relies on local database to work (it allows
My company developed a product that was designed for handsets, but unfortunately tablet owners

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.