How to import all classes from another namespace in PHP

0 votes

I'm implementing namespaces in my existing project. I found that you can use the keyword 'use' to import classes into your namespace. My question is, can I also import all the classes from 1 namespace into another. Example:

namespace foo
{

    class bar
    {

        public static $a = 'foobar';

    }

}

namespace
{
    use \foo;  //This doesn't work!
    echo bar::$a;
}
Oct 20, 2020 in PHP by kartik
• 37,510 points
4,618 views

1 answer to this question.

0 votes

Hello @kartik,

This is not possible in PHP.

All you can do is:

namespace Foo;

use Bar;

$obj = new Bar\SomeClassFromBar();

Hope it helps!!

answered Oct 20, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
0 answers

How to access function value in another function in PHP Classes

How can I return a variable value ...READ MORE

Jun 10, 2022 in PHP by narikkadan
• 63,420 points
802 views
0 votes
1 answer

How to call function of one php file from another php file and pass parameters to it?

Hello @kartik, Include the first file into the ...READ MORE

answered Aug 27, 2020 in PHP by Niroj
• 82,880 points
24,183 views
0 votes
1 answer

How to delete all files from a folder using PHP?

Hello @kartik, Use this: $files = glob('path/to/temp/*'); // get ...READ MORE

answered Sep 14, 2020 in PHP by Niroj
• 82,880 points
1,098 views
0 votes
1 answer

How to copy a file from one directory to another using PHP?

Hello @kartik, You could use the copy() function : // Will ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,880 points
1,099 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,880 points
3,689 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,880 points
2,898 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,880 points
818 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,880 points
756 views
0 votes
1 answer

How to select all records from one table that do not exist in another table?

Hello @kartik, You can either do like this: SELECT ...READ MORE

answered Jul 21, 2020 in PHP by Niroj
• 82,880 points
51,434 views
0 votes
1 answer

How to convert from MySQL datetime to another format with PHP?

Hello, To convert a date retrieved from MySQL ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,880 points
2,934 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP