|
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 |
cartbeforehorse Smarty n00b
Joined: 17 Feb 2016 Posts: 4
|
Posted: Wed Feb 17, 2016 4:41 pm Post subject: Should plugin-functions initiate auto-loading? |
|
|
Smarty version 3.1.29.
My application has an auto-loader function which which I put on the PHP auto-load stack with spl_autoload_register(). This works fine on the whole (and worked fine in older versions of Smarty).
When instigating the plug-in function "load_po" in my *.tpl file, my Auto-loader function raises an error in the application, saying that it cannot find a class called "Smarty_Internal_Compile_load_po".
At first, I wondered why the Smarty auto-loader wasn't being instigated. However, with further investigation, I realised that it was being instigated, but failing to find the class (hence passing the call onto my secondary auto-loader).
I traced the source of the auto-loading initiator to a file called "smarty_internal_templatecompilerbase.php". Function "callTabCompiler()". At line 860/861, the logic appends the string the string "Smarty_Internal_Compile_[b]" to the function name ("[b]load_po"), and then checks whether it exists as a class, as follows:
Code: |
$class_name = 'Smarty_Internal_Compile_' . implode('_',$_tag);
if (class_exists($class_name) &&...
|
Of course, this class does not exist in either the Smarty framework, or my application, so both auto-loaders fail to find it. The problem (as I said earlier) is that my auto-loader errors when a file is not found. (This can be remedied, of course).
However, putting the work-around aside, it seems to me that it is a a bug to search for the class "Smarty_Internal_Compile_load_po". When I change the function "callTagCompiler()" from
Code: | class_exists($class_name) |
to
Code: | class_exists($class_name,false) |
the problem goes away.
Does the community agree that this is a bug? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 17, 2016 6:40 pm Post subject: |
|
|
This is a bug.
In your autoloader.
Autoloader MUST NOT throw errors in case it is unable to load something.
You never know, if your loader is last to be called, and you throwing errors prevent any other loaders to be called. |
|
Back to top |
|
cartbeforehorse Smarty n00b
Joined: 17 Feb 2016 Posts: 4
|
Posted: Wed Feb 17, 2016 10:58 pm Post subject: |
|
|
AnrDaemon wrote: | This is a bug.
In your autoloader.
Autoloader MUST NOT throw errors in case it is unable to load something.
You never know, if your loader is last to be called, and you throwing errors prevent any other loaders to be called. |
Fair enough, I suppose.
But at the same time, I feel it worth noting that my autoloader is designed for an end-user application. The framework is not designed to be extended or added to in the same was that Smarty and other middle-tier solutions are. If a file cannot be found, then there is a problem somewhere, that needs to be brought to attention in some way. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Feb 17, 2016 11:43 pm Post subject: |
|
|
Once more, if all autoloading means are exhausted, but a class still can not be instantiated, PHP will throw an error by itself.
You don't need to do anything at all to make it happen. The work has been cut out for you years ago. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Mar 01, 2016 1:15 am Post subject: |
|
|
If your autoloader throws an error if a class is not found it breaks the functionality of the PHP class_exits() function.
If you change the Smarty code to class_exists(..., false) you will brake the function of Smarty. |
|
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
|