Hi Andi-

Yes, that explains things and makes perfect sense if you are just writing your
own web application. Now, consider the new __autoload functionality from a PEAR
or other large API/library developer standpoint.


The new __autoload functionality lets us:
- Keep library usage/installation simple by only requiring the user to include one
include file regardless of how many possible classes or other files may be
needed. This 'initialization' file will setup a special autoloader for just that library.
If the user happens to use their own autoloader, then they have to simply
setup something like- if (eregi('^libclass_', $className)) {
somelib::autoload($className); }
A 1, with an optional 2 step install process, regardless of which parts of the
library may be used is a good thing. :)
- Keeps the performance of the library up because it now only needs to load
class objects the user actually uses.


The new exception handling also lets a library developer easily document and let a
user know that mylib will throw exception x, y and z.


With that in mind, it's always good practice when writing an API/library to throw the
most informative errors possible. Normally, this would also include errors such as
"Unable to initialize library 'mylib' because file 'foo.inc' could not be found. Please check
install documentation.". A much nicer exception/error than Fatal Error in mylib. This
would also allow the user to catch the error and handle it themself, and at their
sole discretion choosing to continue on with script execution.


These are just my thoughts and observations after writing a large API/library in
PHP5-


Dan Cox

Andi Gutmans wrote:

Dan,

__autoload() is the last chance to load a class which is needed before erroring out and terminating the script. By design, if you don't take advantage of this last chance the script will error out. Therefore, throwing an exception inside the __autoload() function should not be catchable by your script.

I hope that explains things.

Andi


-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to