Is it good practice, or could it be, to force the user to use namespaces in a framework context?
I’m developing a framework (yes, I know, there’s no need of it because of those awesome framework already build; so there’s no need to point out that I’m reinventing the wheel for no reason; this is just for me; I need to be able to build a framework to be in peace with myself;) and I was wondering if forcing the user to use something like:
$post = new Model\Post($id); // for models
$html = new Library\Html(); // for library classes
$ajax = new Helper\Ajax(); // for helpers
# ... and so on
would be acceptable. I need of it to be able to use the autoloading function and automatically check in the right class folder (model/, library/, helper/ … and so on) by the namespace of the class.
Or should I just go with a generic $this referring to the parent controller class and load stuff like:
$post = $this->model('Post');
$html = $this->library('Html');
$ajax = $this->helper('Ajax');
If the latter, how should I manage the parameters that could be sent to the constructor of that class?
Use namespaces. PHP 5.2 is no longer actively supported and the 5.3 version is considered stable. Don’t write new code with the old methodologies unless you are attempting to support a legacy system.
Namespaces are definitely recommended and help out with a lot of problems, including the one you mentioned in regards to autoloading classes.