Jump to content

Search the Community

Showing results for tags 'namespaces'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi I have just recently tried to incorporate namespaces into my framework but having trouble understanding how I should use them in my project. I have a class called Foo which is part of the namespace \CompanyName\Project. namespace \CompanyName\Project; class Foo { } I have a file called index.php. index.php needs to use that class. index.php handles the autoloading of that class (ive omitted the autoloading code). My index.php looks like below. $foo = new Foo(); This code fails because it can't find class Foo. I can make it work by using the fully qualified name instead. $foo = new \CompanyName\Project\Foo(); I can also make it work by making index.php part of \Company\Project\ namespace. namespace \CompanyName\Project; $foo = new Foo(); Basically my problem is that I have lots of different file includes for individual pages on my site. They all use the old unqualifed class names which are not getting resolved by PHP because it can no longer find them as all of the classes now belong to a namespace. Do I A - Go through every included file and change every class name to the fully qualifed class name? B - Go through every included file and make every file part of the \CompanyName\Project namespace (This feels like the wrong solution)? C - Make PHP treat the old unqualifed class name as a global through use of the 'use' statement. I don't know how to do this. The trouble is there could be 10 - 20 different classes per file which would mean 20 different use declarations. Ideally it would be great if I could import an entire namespace into the global namespace like "use \CompanyName\Project as \;". Basically I want a way to move all classes and functions from a particular namespace into the global namespace so I can use the unqualifed class names throughout the included files. And I want to be able to do it from one file, index.php. I don't think this is possible though as PHP does state I think it will have to be option A , before I begin, am I on the right track?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.