Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm currently building my own framework, which should help me create projects faster in the future. Currently it's not so much a framework, but rather a collection of objects that make tedious tasks simpler. For example, I have classes for HTML form inputs, such as select, textbox, etc. I have another class for MySQL, which handles the connection, and all queries. However, as I create more, I realize the need for some kind of automatic include system, so I dont need 100 include statements at the top of my page. My solution was a custom object init function. Instead of using 'new', I would use this function to create a new object. It will first check if the class is defined, and include it if needed. I am using namespaces, which are really just file paths, separated by periods. For example, "html.forms.select" would refer to "/html/forms/select.class.php".
Here is my function:
(I realize that the arguments var will only pass one argument, i'm working on that)
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
If you take a look a the current practice (things like the Zend Framework) they usually will load the class named "This_Is_My_Class" from the file "This/Is/My/Class.php". Which means they don't just use the last word in the "namespaced" name passed.
In a nutshell, this function will be called whenever you create a new object. This function will be in charge of finding the file and loading it into memory.