467,894 Members | 1,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Best way of calling multiple classes?

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
Aug 28 '07 #1
  • viewed: 1365
Share:
11 Replies
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

Aug 28 '07 #2
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.
js*******@attglobal.net
==================
Aug 29 '07 #3
RTFM about __autoload().

Thank you, I most certainly will.

Cheers

Phil
Aug 29 '07 #4
..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
Aug 29 '07 #5
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.
js*******@attglobal.net
==================
Aug 29 '07 #6
..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
Aug 29 '07 #7

"Michael Fesser" <ne*****@gmx.dewrote in message
news:ct********************************@4ax.com...
.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
Aug 29 '07 #8
On Aug 29, 4:06 am, gosha bine <stereof...@gmail.comwrote:
>
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?

Aug 29 '07 #9
ZeldorBlat wrote:
On Aug 29, 4:06 am, gosha bine <stereof...@gmail.comwrote:
>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?
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.
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Aug 29 '07 #10
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.)
Aug 29 '07 #11
..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
Aug 29 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Martin Maney | last post: by
14 posts views Thread by Axel Straschil | last post: by
3 posts views Thread by Sasha | last post: by
12 posts views Thread by Perre Van Wilrijk | last post: by
3 posts views Thread by =?Utf-8?B?TWljaGFlbA==?= | last post: by
1 post views Thread by =?Utf-8?B?cmFuZHkxMjAw?= | last post: by
7 posts views Thread by Ashutosh Bhawasinka | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.