JLoader::import

452 views
Skip to first unread message

Rafael Diaz-Tushman from Dioscouri

unread,
Nov 24, 2009, 6:30:26 PM11/24/09
to Joomla! CMS Development
In the context of Joomla 1.5, which (as I understand it) is going to
maintain PHP4 compatibility, is there a particular reason why
JLoader::import uses an include statement as opposed to either of the
_once statements (include_once or require_once)?

The include statement causes issues (double declarations) when a
plugin/module uses JLoader::import to include a class file that is
later also included via JLoader::import in a component.

This could be resolved by changing line 80 of /libraries/joomla/
loader.php to include_once instead of include

Opposition to the idea seems to stem from a supposed performance hit
that include_once suffers vs include, but I can't find published tests
that substantiate the claim of a performance hit. Additionally, when
thinking logically about the difference in execution time/memory usage
this might actually cause, I think it is negligible compared to the
cost (a PHP Warning).

Then again, I also don't mind typing include_once (or require_once) as
opposed to JLoader::import() -- it's just that when writing for
Joomla, I try to use Joomla's classes.

Cheers.





Andrew Eddie

unread,
Nov 24, 2009, 8:06:32 PM11/24/09
to joomla-...@googlegroups.com
Hi Rafael.

I stumbled upon a comment from Greg Beaver last night which sums up
why you should use include:

http://www.sitepoint.com/blogs/2009/07/15/how-to-use-php-namespaces-part-3-keywords-and-autoloading/#comment-928595

If you are getting duplicate declarations then we need to see why that
is happening because JLoader::import is not supposed to be loading
something more than once. In other words, include is fine but there
must be a but somewhere else.

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer




2009/11/25 Rafael Diaz-Tushman from Dioscouri <rdiazt...@dioscouri.com>:

Andrew Eddie

unread,
Nov 24, 2009, 8:09:11 PM11/24/09
to joomla-...@googlegroups.com
Sorry, there must be a "bug" somewhere else.

Can you give me an example of where you can get a duplicate
declaration happening?

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer

2009/11/25 Andrew Eddie <mamb...@gmail.com>:

Rafael Diaz-Tushman from Dioscouri

unread,
Nov 26, 2009, 9:21:21 AM11/26/09
to Joomla! CMS Development
I will attempt to recreate it with one of the core helper files and a
system plugin for you. I'll get it to you after the holiday. Cheers.

On Nov 24, 8:09 pm, Andrew Eddie <mambob...@gmail.com> wrote:
> Sorry, there must be a "bug" somewhere else.
>
> Can you give me an example of where you can get a duplicate
> declaration happening?
>
> Regards,
> Andrew Eddiehttp://www.theartofjoomla.com- the art of becoming a Joomla developer
>
> 2009/11/25 Andrew Eddie <mambob...@gmail.com>:
>
>
>
> > Hi Rafael.
>
> > I stumbled upon a comment from Greg Beaver last night which sums up
> > why you should use include:
>
> >http://www.sitepoint.com/blogs/2009/07/15/how-to-use-php-namespaces-p...
>
> > If you are getting duplicate declarations then we need to see why that
> > is happening because JLoader::import is not supposed to be loading
> > something more than once.  In other words, include is fine but there
> > must be a but somewhere else.
>
> > Regards,
> > Andrew Eddie
> >http://www.theartofjoomla.com- the art of becoming a Joomla developer
>
> > 2009/11/25 Rafael Diaz-Tushman from Dioscouri <rdiaztush...@dioscouri.com>:

Rafael Diaz-Tushman

unread,
Mar 13, 2010, 11:42:05 AM3/13/10
to joomla-...@googlegroups.com
Sorry to be following up on this so late!  It has been a hectic few months.

Would there be interest in adding an optional argument $className to JLoader::import(), changing it from

JLoader::import($filePath, $base = null, $key = 'libraries.')

to

JLoader::import($filePath, $base = null, $key = 'libraries.', $className=null)

I ask because with a few more slight modifications to the rest of that method, we could allow non-joomla-namespace files to also be added to the autoloader directly from JLoader::import (as is done on line 62 of loader.php for joomla-namespace methods)

Cheers.

--
Rafael Diaz-Tushman, President & CEO
Dioscouri Design: Form and Function
www.dioscouri.com
www.twitter.com/dioscouri


On Sat, Mar 13, 2010 at 11:29 AM, Rafael Diaz-Tushman from Dioscouri <rdiazt...@dioscouri.com> wrote:



---------- Forwarded message ----------
From: Rafael Diaz-Tushman from Dioscouri <rdiaztush...@dioscouri.com>
Date: 26 Nov 2009, 09:21
Subject: JLoader::import
To: Joomla! CMS Development


I will attempt to recreate it with one of the core helper files and a
system plugin for you.  I'll get it to you after the holiday.  Cheers.

On Nov 24, 8:09 pm, Andrew Eddie <mambob...@gmail.com> wrote:



> Sorry, there must be a "bug" somewhere else.

> Can you give me an example of where you can get a duplicate
> declaration happening?

> Regards,
> Andrew Eddiehttp://www.theartofjoomla.com-the art of becoming a Joomla developer


> 2009/11/25 Andrew Eddie <mambob...@gmail.com>:

> > Hi Rafael.

> > I stumbled upon a comment from Greg Beaver last night which sums up
> > why you should use include:

> >http://www.sitepoint.com/blogs/2009/07/15/how-to-use-php-namespaces-p...

> > If you are getting duplicate declarations then we need to see why that
> > is happening becauseJLoader::import is not supposed to be loading

> > something more than once.  In other words, include is fine but there
> > must be a but somewhere else.

> > Regards,
> > Andrew Eddie
> >http://www.theartofjoomla.com-the art of becoming a Joomla developer


> > 2009/11/25 Rafael Diaz-Tushman from Dioscouri <rdiaztush...@dioscouri.com>:

> >> In the context of Joomla 1.5, which (as I understand it) is going to
> >> maintain PHP4 compatibility, is there a particular reason why
> >>JLoader::import uses an include statement as opposed to either of the
> >> _once statements (include_once or require_once)?

> >> The include statement causes issues (double declarations) when a
> >> plugin/module usesJLoader::import to include a class file that is
> >> later also included viaJLoader::import in a component.


> >> This could be resolved by changing line 80 of /libraries/joomla/
> >> loader.php to include_once instead of include

> >> Opposition to the idea seems to stem from a supposed performance hit
> >> that include_once suffers vs include, but I can't find published tests
> >> that substantiate the claim of a performance hit.  Additionally, when
> >> thinking logically about the difference in execution time/memory usage
> >> this might actually cause, I think it is negligible compared to the
> >> cost (a PHP Warning).

> >> Then again, I also don't mind typing include_once (or require_once) as
> >> opposed toJLoader::import() -- it's just that when writing for
Reply all
Reply to author
Forward
0 new messages