From: "Michael N. Madsen" on
Since php started to support oop it has moved more and more features in that
direction.
This is good for me because I love oop. Then came _autoload() and I was
rejoiced only to find that this (no fun)ction can't be used to it's fullest
potential in oop unless I have all the files in the same directory. This is
where you correct me and tell me how I can have a file structure in more
then one level and still get the ripe juices of _autoload() (Please, I beg
you!)

I have looked at the comments on the doc page of the function and every
single one comes with the addition of many, often complex lines of code that
will only add more load on the server. If _autoload can't figure out the
correct path to the file which defines the class, then what is the point
from an oop pov?

From: "Jo�o C�ndido de Souza Neto" on
I use this in a different way so I think it can be useful for everyone
avoiding long and complex codes.

I�ve got a file called classes.php that looks like:

<?php

$Classes = new stdClass();

$Classes->Smarty = BASE_PATH."includes/Smarty/Smarty.class.php";

$Classes->Mail = BASE_PATH."includes/mail/Mail.php";

?>

So my _autoload() looks like:

function MY__autoload($className) {

require_once("classes.php")

require_once($Classes->$className);

}

if (function_exists("spl_autoload_register") ) {

spl_autoload_register("MY__autoload");

} else {

function __autoload($className) {

MY__autoload($className);

}

}


Hope it can help you.

""Michael N. Madsen"" <mnm(a)criion.net> escreveu na mensagem
news:62.43.44964.9B05DEB4(a)pb1.pair.com...
> Since php started to support oop it has moved more and more features in
> that direction.
> This is good for me because I love oop. Then came _autoload() and I was
> rejoiced only to find that this (no fun)ction can't be used to it's
> fullest potential in oop unless I have all the files in the same
> directory. This is where you correct me and tell me how I can have a file
> structure in more then one level and still get the ripe juices of
> _autoload() (Please, I beg you!)
>
> I have looked at the comments on the doc page of the function and every
> single one comes with the addition of many, often complex lines of code
> that will only add more load on the server. If _autoload can't figure out
> the correct path to the file which defines the class, then what is the
> point from an oop pov?


From: Peter Lind on
On 14 May 2010 15:31, Michael N. Madsen <mnm(a)criion.net> wrote:
> Since php started to support oop it has moved more and more features in that
> direction.
> This is good for me because I love oop. Then came _autoload() and I was
> rejoiced only to find that this (no fun)ction can't be used to it's fullest
> potential in oop unless I have all the files in the same directory. This is
> where you correct me and tell me how I can have a file structure in more
> then one level and still get the ripe juices of _autoload() (Please, I beg
> you!)
>
> I have looked at the comments on the doc page of the function and every
> single one comes with the addition of many, often complex lines of code that
> will only add more load on the server. If _autoload can't figure out the
> correct path to the file which defines the class, then what is the point
> from an oop pov?

__autoload() is triggered when a class referenced isn't already
loaded. It gives you the chance to load the class by requiring the
needed file - but there's no way PHP has any idea of how many files
you have in your project, so YOU have to tell PHP which file to load.
This, to most people, means coming up with a meaningful way of naming
files and classes so you can parse the class name and then know where
to grab the file from (Zend naming for instance:
Zend_Db_Table_Abstract gets parsed to Zend/Db/Table/Abstract.php). So
no, you don't have to stress the server a lot - but you do have to do
some manual work.

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>
From: Nathan Nobbe on
On Fri, May 14, 2010 at 7:31 AM, Michael N. Madsen <mnm(a)criion.net> wrote:

> Since php started to support oop it has moved more and more features in
> that direction.
> This is good for me because I love oop. Then came _autoload() and I was
> rejoiced only to find that this (no fun)ction can't be used to it's fullest
> potential in oop unless I have all the files in the same directory. This is
> where you correct me and tell me how I can have a file structure in more
> then one level and still get the ripe juices of _autoload() (Please, I beg
> you!)
>

umm ok ill correct you.., theres no requirement to have files in a single
directory. php gives you the name of a class and you are responsible for
finding the file where the class lives and load it.


> I have looked at the comments on the doc page of the function and every
> single one comes with the addition of many, often complex lines of code that
> will only add more load on the server.


actually, autoloading typically reduces load on the server b/c only the
files you actually need for a given request are loaded on demand. this in
contrast to requires/includes for every possible class that could
potentially be needed to fulfill a given request.


> If _autoload can't figure out the correct path to the file which defines
> the class, then what is the point from an oop pov?


see above; its a speed boost, and typically folks prefer not to bother
include/require files atop ever class the define; those are the 2 main
benefits.

-nathan