Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

smartyAutoload vs. include/include_once

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
magicmulder
Smarty n00b


Joined: 04 Feb 2015
Posts: 2

PostPosted: Wed Feb 04, 2015 9:48 am    Post subject: smartyAutoload vs. include/include_once Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1530

PostPosted: Wed Feb 04, 2015 3:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
magicmulder
Smarty n00b


Joined: 04 Feb 2015
Posts: 2

PostPosted: Wed Feb 04, 2015 3:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1530

PostPosted: Wed Feb 04, 2015 4:47 pm    Post subject: Reply with quote

Please provide a STC.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Wed Feb 04, 2015 8:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1530

PostPosted: Wed Feb 04, 2015 9:23 pm    Post subject: Reply with quote

Isn't that what is called "overengineering"?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Thu Feb 05, 2015 6:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP