Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Best way of calling multiple classes?

 
   Database Forums (Home) -> PHP RSS
Next:  how do I set up multiple diaries in MS Access?  
Author Message
Phil Latio

External


Since: Nov 16, 2003
Posts: 18



(Msg. 1) Posted: Tue Aug 28, 2007 8:58 pm
Post subject: Best way of calling multiple classes?
Archived from groups: comp>lang>php (more info?)

I'm designing a small framework with a lot of classes (1 file per class) and
want to know the best method of calling each class?

Obviously I could I call each file that is used but that could be 10 or more
include statements. I am wonering if there is a better way? It's bit
annoying you can't build packages like Java.

Cheers

Phil

 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 2) Posted: Tue Aug 28, 2007 8:58 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Phil Latio wrote:
> I'm designing a small framework with a lot of classes (1 file per class) and
> want to know the best method of calling each class?
>
> Obviously I could I call each file that is used but that could be 10 or more
> include statements. I am wonering if there is a better way? It's bit
> annoying you can't build packages like Java.
>
> Cheers
>
> Phil
>
>

I just put in the include statements.

Actually, I don't use include - I use require_once. And if a class
depends on another class (often in my case), the require_once goes in
the requiring file.

That way the main file only needs to worry about what it needs, as each
file takes care of its own includes.

__autoload is good - but it requires extra processing over and above a
require_once, and pretty much everything has to reside in the same
directory.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex.DeleteThis@attglobal.net
==================

 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Phil Latio

External


Since: Nov 16, 2003
Posts: 18



(Msg. 3) Posted: Tue Aug 28, 2007 10:59 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> RTFM about __autoload().

Thank you, I most certainly will.

Cheers

Phil
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Michael Fesser

External


Since: Mar 01, 2006
Posts: 315



(Msg. 4) Posted: Tue Aug 28, 2007 10:59 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(Jerry Stuckle)

>__autoload is good - but it requires extra processing over and above a
>require_once, and pretty much everything has to reside in the same
>directory.

My __autoload() invokes a special class loader method, which allows to
store all my classes and interfaces in subdirectories. The class loader
is able to recursively search through the tree structure if necessary.
The exact location of each found class is cached in an index file, so
the overhead for loading a class is quite small.

Micha
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 5) Posted: Tue Aug 28, 2007 10:59 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> __autoload is good - but it requires extra processing over and above a
>> require_once, and pretty much everything has to reside in the same
>> directory.
>
> My __autoload() invokes a special class loader method, which allows to
> store all my classes and interfaces in subdirectories. The class loader
> is able to recursively search through the tree structure if necessary.
> The exact location of each found class is cached in an index file, so
> the overhead for loading a class is quite small.
>
> Micha

Not bad. But it also adds complexity and overhead.

Don't get me wrong - I like __autoload. But I also like to keep things
simple. Make for much easier troubleshooting in six months.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex RemoveThis @attglobal.net
==================
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Phil Latio

External


Since: Nov 16, 2003
Posts: 18



(Msg. 6) Posted: Wed Aug 29, 2007 1:09 am
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> I just put in the include statements.
>
> Actually, I don't use include - I use require_once. And if a class
> depends on another class (often in my case), the require_once goes in the
> requiring file.

This is what I doing now. I am just getting fed up with it.

> __autoload is good - but it requires extra processing over and above a
> require_once, and pretty much everything has to reside in the same
> directory.

I had heard of __autoload before but never realised what it did. I did a
Google after getting the other reply and came across
http://tobias-demuth.de/en/index.htm which looks interesting. Bit
frustrating that the author hasn't included some examples and a bit more
documentation because I don't fully understand how it supposed to work.

Cheers

Phil
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Iván_Sánchez_Ortega

External


Since: Oct 12, 2005
Posts: 45



(Msg. 7) Posted: Wed Aug 29, 2007 1:53 am
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Phil Latio wrote:

> I'm designing a small framework with a lot of classes (1 file per class)
> and want to know the best method of calling each class?
>
> Obviously I could I call each file that is used but that could be 10 or
> more include statements. I am wonering if there is a better way? It's bit
> annoying you can't build packages like Java.

RTFM about __autoload().

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.22-1-amd64 kernel, KDE 3.5.7, and PHP
5.2.3-1+b1 generating this signature.
Uptime: 01:52:55 up 7 days, 22:13, 5 users, load average: 0.28, 0.31, 0.43
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Michael Fesser

External


Since: Mar 01, 2006
Posts: 315



(Msg. 8) Posted: Wed Aug 29, 2007 6:58 am
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(Jerry Stuckle)

>Not bad. But it also adds complexity and overhead.

Yep, but it pays off for me. I profile my code from time to time and the
real bottlenecks are always somewhere else.

>Don't get me wrong - I like __autoload. But I also like to keep things
>simple. Make for much easier troubleshooting in six months.

Point taken, but for me it has real advantages. My entire framework has
become rather complex and is still growing. I also have to change the
directory structure from time to time to clean things up (there are
still some ugly things left from the early days of that class library,
which have to be improved). So it makes things a lot easier if I can let
the library perform some rather common tasks automatically.

A while ago I also thought about something like an import() function,
which could have worked like the 'import' statement in Java:

import('/path/to/classes/TFoo'); // load a single class
import('/path/to/classes/*'); // load all classes in that directory

But then PHP 5 and __autoload() came up ...

Another interesting approach I once saw (IIRC in the Prado framework,
but I'm not sure) was something like the import() above, but the
function didn't load the classes, but just added the supplied path to
PHP's include_path. Then the class could easily require_once all other
required classes without having to worry about the directory structure.

Micha
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
ZeldorBlat

External


Since: Jun 11, 2007
Posts: 37



(Msg. 9) Posted: Wed Aug 29, 2007 11:03 am
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Aug 29, 4:06 am, gosha bine wrote:
>
> autoload is rather a dirty hack and as such should be avoided.
>

Why do so many people say this? autoload does exactly what it was
intended to do and it works perfectly. It solved a major problem that
people had complained about for a long time. Would you care to
elaborate on your objections to using it?
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Michael Fesser

External


Since: Mar 01, 2006
Posts: 315



(Msg. 10) Posted: Wed Aug 29, 2007 11:25 am
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(Phil Latio)

>I had heard of __autoload before but never realised what it did. I did a
>Google after getting the other reply and came across
>http://tobias-demuth.de/en/index.htm which looks interesting. Bit
>frustrating that the author hasn't included some examples and a bit more
>documentation because I don't fully understand how it supposed to work.

I had a look at the code - I wouldn't use it. The code is ugly and has a
really big bug: The function that searches the class tree is called on
every __autoload() call, which pretty much defeats the purpose of having
a cache file. It's easy to fix (just a missing 'else'), but nevertheless
that shouldn't happen.

Micha
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Phil Latio

External


Since: Nov 16, 2003
Posts: 18



(Msg. 11) Posted: Wed Aug 29, 2007 12:01 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Michael Fesser" wrote in message

> .oO(Jerry Stuckle)
>
>>__autoload is good - but it requires extra processing over and above a
>>require_once, and pretty much everything has to reside in the same
>>directory.
>
> My __autoload() invokes a special class loader method, which allows to
> store all my classes and interfaces in subdirectories. The class loader
> is able to recursively search through the tree structure if necessary.
> The exact location of each found class is cached in an index file, so
> the overhead for loading a class is quite small.

Did you write this yourself did you download it from somewhere? Sounds like
just what I am after.

Cheers

Phil
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Sanders Kaufman

External


Since: Jan 10, 2007
Posts: 108



(Msg. 12) Posted: Wed Aug 29, 2007 4:01 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

gosha bine wrote:

> autoload is a "magic quotes"-type of solution to me: it attempts to
> solve the real problem, but at the wrong place and in the wrong way.
> Besides that, it's "magic" (which stinks like hell) and it's global
> (which stinks even more).
>
> We don't need yet another stinky "magic" quick fix in php. We do need a
> decent packaging system and the catchable ClassNotFound exception.

I gotta say - that whole "magic" thing really turns me off. I'm sure
someone somewhere has good use for it - but as an engineering type, I
get real nervous when folks start naming their algorithms after concepts
from fantasy novels.

I just seems so... deprecable.

(And if I see one more security server named "gandalf", I swear to God
I'll put on a suicide vest and blow the damned thing up myself. - Just
kidding - hahahaha.)
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Michael Fesser

External


Since: Mar 01, 2006
Posts: 315



(Msg. 13) Posted: Wed Aug 29, 2007 8:00 pm
Post subject: Re: Best way of calling multiple classes? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

..oO(gosha bine)

>autoload is a "magic quotes"-type of solution to me: it attempts to
>solve the real problem, but at the wrong place and in the wrong way.
>Besides that, it's "magic" (which stinks like hell)

__set(), __get(), __call() ... all "magic", but very useful from time to
time. If you don't like them, simply don't use them.

Micha
 >> Stay informed about: Best way of calling multiple classes? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Can someone wxplain classes to me please - the why not wha.. - I understand what a class is but am confused as to why so many people are using them for what appear to be very simple PHP applications. I guess I dont know enough about how they are useful. for example I've just seen a "who is" application ...

Symbols used in classes. - Hi all., Probably an old quesion, but im pretty new to php, and have not had great success in searching. Ive looking over some code which contains the following terms $this -> :: And have not clue as to what they mean. I have been looking at the ph...

Plugin system: Automatically instantiate included classes? - Hi there, I am planning to implement a plugin system, based on the observer pattern in some way, but now I am stuck with the instantiation of the plugins. I want the plugins to have their own class, abstracted from the class Plugin. So far its nothing....

Text-to-MathML Output: Calling Javascript - Background: 1. These days there is a very cool (useful) way of getting MathML by using a pseudo-math notation in plaintext. This was originally written in Javascript by Peter Jipsen (see http://www1.chapman.edu/ ~jipsen/mathml/asciimath.xml). 2. A..

Using C libraries and PHP - calling functions in external .. - Currently I am running a compiled C program (called swetest) on Linux from PHP using the exec() command. This allows me to get the calculations I need. But some web hosts out there disable the exec() command and I am stuck. What are the ways in which ...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]