SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2011
    0 Post(s)
    0 Thread(s)

    Question Namespaces, Filenames and Autoload

    Hi all, I have started work on my new PHP web app and before getting too far would like to ensure I am following best practices for file naming and namespaces so that I can use an autoload function effectively.

    I have read up on PSR-0 and have a question: What would the vendor name be in an web application I am building, simply the project name?

    Additionally, I currently have the following structure (no namespaces and my class names match the filenames), I'd like to work out the best way to name the folders, filenames, namespaces and classes?

    • Should the namespace for BaseController be MyProject\App\Core, or
    • Should the namespace for BaseController be MyProject\App and the class name Core_BaseController?
    • Should I rename my folders to all use upper camel case? (eg. App, Core, etc)
    • Should my class names remain in upper camel case?
    • Should my directories all be singular or plural? Does it matter?

    Lastly, I have had a look at the recommended SplClassLoader here:

    If I follow the above standards would I then need to register with:

    PHP Code:
    $classLoader = new SplClassLoader('MyProject\App\Core''../App/Core');

    $classLoader = new SplClassLoader('MyProject\App\Controllers''../App/Controllers');

    $classLoader = new SplClassLoader('MyProject\App\DataMappers''../App/DataMappers');
    This seems like horrible overkill. Can this be done more efficiently?

    Last edited by Jordan Windebank; Dec 30, 2013 at 01:43. Reason: Fixed slash direction in namespace examples.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts