i have studied design patterns and want to use them to code an open source library (not an application).
but i have never coded a library before and don't know where should i include files, should i have a bootstrap file that loads everything or should every class load their own classes they are dependent on etc.
are there any tutorials for writing libraries in php from start to finnish?
thanks
I can't point you to a tutorial, but the easiest way to have a plug and play library is to have one class per class file, so that the user has the option to use __autoload and simply instantiate your classes without having to change anything in their existing code. This way is most accessible to most developers.
This method still allows you to create one 'standalone' include file that includes all your other class files.
Other options include making it into a PEAR package or asking people to place your files in the include path. However this is not optimal in my opinion for people who don't have access to anything other than their own public_html folder (on shared hosting, for example).
You should have a look at the Solarphp Framework. It solves like every other frameworks some standard issues like autoloading, dependeny injection etc... I learned a lot about writing good php code from it. If you have questions join #solar-talk at freenode
I'd point you to Zend Framework. You can use it as a whole framework, but can also use selected components as you like. yes, i think to a library, autoloading is the key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With