|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
magicmulder Smarty n00b
Joined: 04 Feb 2015 Posts: 2
|
Posted: Wed Feb 04, 2015 9:48 am Post subject: smartyAutoload vs. include/include_once |
|
|
I'm curious why Smarty.class in function smartyAutoload() is using "include" instead of "include_once".
I've seen scenarios (which were hard to reproduce) where there were "cannot redeclare class ..." errors related to Smarty sys classes in the log.
Since the method loads internal class definitions only, I don't see why potentially loading them multiple times make any sense.
Or am I missing something? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 04, 2015 3:02 pm Post subject: |
|
|
Since it is **auto**load, it will only be called, if class is not defined. Means, it will never be called more than once.
With include vs. require, using include ensure that you still have room to gracefully terminate application, if class fails to load. |
|
Back to top |
|
magicmulder Smarty n00b
Joined: 04 Feb 2015 Posts: 2
|
Posted: Wed Feb 04, 2015 3:06 pm Post subject: |
|
|
Obviously there are circumstances where it can be loaded multiple times or I wouldn't see "cannot redeclare class" w.r.t. a Smarty sys class (no, it's not coming from other parts of the code including Smarty multiple times).
And I was asking why "include()" instead of "include_once()", not why "include()" instead of "require()". |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 04, 2015 4:47 pm Post subject: |
|
|
Please provide a STC. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 04, 2015 8:06 pm Post subject: |
|
|
Which class does produce the error?
As mentioned before the autoloader will never load a class multiple times.
Anyway in the next version 3.1.22 the autoloader has been rewritten and moved into its own class to make Smarty better compatible with composer and its autoloading.
You can download the current status of the upcomming version 3.1.22 from https://github.com/smarty-php/smarty |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 04, 2015 9:23 pm Post subject: |
|
|
Isn't that what is called "overengineering"? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Feb 05, 2015 6:57 pm Post subject: |
|
|
Not at all.
We have now up to several hundreds installs a day via github and composer.
We will in future automatically detect the composer autoloader and use that if present. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot 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
|
Powered by phpBB © 2001, 2005 phpBB Group
|