How to give a PHP-include its own namespace (like "from a import MyClass" in Python)? -
i've got little experience in php, come python. thing adore python way modules handled. if have file called a.py in directory, containing class called myclass can import class this.
from import myclass
from php however, know can do:
include somefile.php
this imports , runs code file, makes similar following in python
from import *
doing wildcard import however, leaves me clueless importing , causes namespace pollution. question; there way can import classes in php naming them?
the practice in php 1 class per file, not classes in same file module
ex:
classes/mynamespace/mypackage/io.php classes/mynamespace/mypackage/db.php classes/mynamespace/mypackage/log.php ...
then use autoloader, every time need class in code, autoloader kicks in , loads it. if not using framework comes built-in autoloader, solution use autoloader provided composer, depedncy manager php: http://getcomposer.org/
Comments
Post a Comment