View previous topic :: View next topic |
Author |
Message |
tvdw Smarty n00b
Joined: 31 Oct 2009 Posts: 3
|
Posted: Sat Oct 31, 2009 7:32 pm Post subject: spl_autoload issue |
|
|
Hey there,
My system, which uses its own spl_autoload as well, had problems with the spl_autoload_register of smarty.
Code: | Index: core/smarty/Smarty.class.php
===================================================================
--- core/smarty/Smarty.class.php (revision 3294)
+++ core/smarty/Smarty.class.php (working copy)
@@ -91,7 +91,7 @@
spl_autoload_extensions('.php,.inc');
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
- spl_autoload_register();
+ spl_autoload_register('smartyAutoload');
}
} else {
spl_autoload_register('smartyAutoload'); |
The above fixed it.
I load smarty via my appAutoload function, which is registered by
Code: | spl_autoload_register('appAutoload'); |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Nov 01, 2009 1:52 am Post subject: |
|
|
Smarty tries to use the default spl_autoload() of php if possible for speed, otherwise it falls back to smartyAutoload. What wasn't working? |
|
Back to top |
|
mrearl33 Smarty n00b
Joined: 01 Nov 2009 Posts: 2
|
Posted: Sun Nov 01, 2009 10:09 am Post subject: |
|
|
Hi, I have the same problem with Zend_Loader from ZendFramework
The problem occurs when an autoloader is already registered but not the default spl_autoload.
I think a better fix is :
Code: |
Index: tools/smarty/Smarty.class.php
===================================================================
--- tools/smarty/Smarty.class.php (révision 3294)
+++ tools/smarty/Smarty.class.php (copie de travail)
@@ -88,14 +88,17 @@
* register the class autoloader
*/
if (set_include_path(SMARTY_SYSPLUGINS_DIR . PATH_SEPARATOR . get_include_path()) !== false) {
- spl_autoload_extensions('.php,.inc');
$registeredAutoLoadFunctions = spl_autoload_functions();
- if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
- spl_autoload_register();
- }
+ if(!$registeredAutoLoadFunctions) {
+ spl_autoload_extensions('.inc,.php');
+ spl_autoload_register();
+ } elseif (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
+ spl_autoload_register('spl_autoload');
+ }
} else {
spl_autoload_register('smartyAutoload');
-}
+}
+
/**
* This is the main Smarty class
*/
|
I think it can be shorted to :
Code: |
if (set_include_path(SMARTY_SYSPLUGINS_DIR . PATH_SEPARATOR . get_include_path()) !== false) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
spl_autoload_register('spl_autoload');
}
} else {
spl_autoload_register('smartyAutoload');
}
|
I am using php 5.2.11-1 (from debian sid).
Steeve. |
|
Back to top |
|
tvdw Smarty n00b
Joined: 31 Oct 2009 Posts: 3
|
Posted: Sun Nov 01, 2009 2:03 pm Post subject: |
|
|
mohrt wrote: | Smarty tries to use the default spl_autoload() of php if possible for speed, otherwise it falls back to smartyAutoload. What wasn't working? | Fatal error because the Smarty_Internal_TemplateBase wasn't found.
And yes, mrearl33 is right, spl_autoload_register() doesn't work if there is already an autoload registered. spl_autoload_register('spl_autoload') also fixes the issue |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Nov 01, 2009 4:25 pm Post subject: |
|
|
SVN is updated with a fix, please give it a test and let me know if that worked. |
|
Back to top |
|
mrearl33 Smarty n00b
Joined: 01 Nov 2009 Posts: 2
|
Posted: Sun Nov 01, 2009 4:32 pm Post subject: |
|
|
It works for me
Steeve. |
|
Back to top |
|
thunderx Smarty n00b
Joined: 04 Nov 2009 Posts: 2
|
Posted: Wed Nov 04, 2009 11:21 am Post subject: |
|
|
Mine is combined with Codeigniter1.7.2,
the SVN doesn't work but mrearl33's short one does |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Nov 04, 2009 4:57 pm Post subject: |
|
|
thunderx wrote: | Mine is combined with Codeigniter1.7.2,
the SVN doesn't work but mrearl33's short one does |
What error are you seeing? The SVN patch is very similar to that example. |
|
Back to top |
|
toma Smarty Regular
Joined: 25 Apr 2003 Posts: 62
|
Posted: Thu Nov 05, 2009 1:29 am Post subject: |
|
|
I just solved a problem I thought was related to this. Using 5.3 I would receive
"Fatal error: Class 'Smarty_Internal_Template' not found in C:\projects\db\library\pear\Text\Diff.php on line 305"
but Smarty_Internal_Template wasn't in there of course. I finally found it was pear's use of references in a class definition near that line:
class Text_Diff_Op_copy extends Text_Diff_Op {
function &reverse()
{
$reverse = new Text_Diff_Op_copy($this->final, $this->orig);
return $reverse;
}
}
Getting rid of the & fixed the not found error. |
|
Back to top |
|
toma Smarty Regular
Joined: 25 Apr 2003 Posts: 62
|
Posted: Thu Nov 05, 2009 2:36 am Post subject: |
|
|
Something else to consider on this topic: users may want to use their autoloader instead of adding a second autoloader on the stack. e.g.
Code: |
class smartyAutoloader Implements Zend_Loader_Autoloader_Interface {
public function autoload($class) {
$_class = strtolower($class);
if (substr($_class, 0, 16) === 'smarty_internal_') {
include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
}
}
}
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->pushAutoloader(new SmartyAutoloader());
|
I've only just begun to explore autoloading in php but this autoloading newbie thinks using the functionality of my chosen framework is preferable. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
thunderx Smarty n00b
Joined: 04 Nov 2009 Posts: 2
|
Posted: Thu Nov 05, 2009 3:28 am Post subject: |
|
|
mohrt wrote: |
What error are you seeing? The SVN patch is very similar to that example. |
Code: | Uncaught exception 'LogicException' with message 'Class CI_Mysmarty could not be loaded'
Stack trace:
#0 Loader.php(879): spl_autoload('CI_Mysmarty')
#1 Loader.php(829): CI_Loader->_ci_init_class('CI_Mysmarty')
#2 Loader.php(96): CI_Loader->_ci_load_class('Mysmarty', '', NULL, NULL)
|
It seems that codeigniter loader will add in the prefix CI_ somehow in the middle |
|
Back to top |
|
|