• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smarty 3.0 - LogicException

#1
[eluser]mvdg27[/eluser]
Hi guys,

Today I decided I wanted to play around with Smarty3.0 (beta) for a bit. But I'm encountering an error, and I don't really understand where it's coming from.

What I've done so far is creating a class called smarty_parser in my Application libraries. The library requires the Smarty 3.0 class (all files are located inside a subfolder smarty3.0 inside the libraries folder) and it extends the Smarty class.

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require "smarty3/Smarty.class.php";

class Smarty_parser extends Smarty {

    function Smarty_parser() {
        print 'ok';
    }

}


I haven't done anything else yet, as this already throws an error ... I found already that the error is caused by requiring the Smarty class. When I comment this out, I don't get this error.

Code:
Fatal error: Uncaught exception 'LogicException' with message 'Class CI_Smarty_parser could not be loaded' in /system/libraries/Loader.php:879
Stack trace:
#0 [internal function]: spl_autoload('CI_Smarty_parser')
#1 /system/libraries/Loader.php(879): class_exists('CI_Smarty_parser')
#2 /system/libraries/Loader.php(829): CI_Loader->_ci_init_class('Smarty_parser', '', NULL, NULL)
#3 /system/libraries/Loader.php(96): CI_Loader->_ci_load_class('smarty_parser', NULL, NULL)
#4 /system/application/controllers/web.php(15): CI_Loader->library('smarty_parser')
#5 /system/codeigniter/CodeIgniter.php(201 in /system/libraries/Loader.php on line 879

Can anyone explain me what could be causing this error? I'm happy to spend some time getting it to work, but it's getting kind of difficult if I don't get what's going wrong Wink

Thanks! -Michiel

#2
[eluser]Mubsel[/eluser]
Hi!

I think this is a problem with the Smarty3 beta. I had a Smarty3 alpha (from svn) running for a few days, and had no problems.

The alpha version had this code in "Smarty.class.php" in line 83.
Code:
spl_autoload_register('smartyAutoload');
Where the beta has
Code:
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();
    }
} else {
    spl_autoload_register('smartyAutoload');
}

When I change this to the "alpha-code" it works again - so the problem has something to do with the new code. I'm trying to find out what the problem is.

Greetz
M.

#3
[eluser]Mubsel[/eluser]
The problems has something to do with line 879 in"/system/libraries/Loader.php" (-> error message).
Code:
if (class_exists('CI_'.$class))
{
    $name = 'CI_'.$class;
}
elseif (class_exists(config_item('subclass_prefix').$class))
{
    echo 'CI_'.$class;
    $name = config_item('subclass_prefix').$class;
}
else
{
    $name = $class;
}

Wrap a try-catch-block around the above code, and it works!
Code:
try
{
    if (class_exists('CI_'.$class))
    {
        $name = 'CI_'.$class;
    }
    elseif (class_exists(config_item('subclass_prefix').$class))
    {
        echo 'CI_'.$class;
        $name = config_item('subclass_prefix').$class;
    }
    else
    {
        $name = $class;
    }
}
catch (Exception $e)
{
    $name = $class;
}

http://bugs.php.net/bug.php?id=39313
and
http://bugs.typo3.org/view.php?id=11176

We are running PHP 5.2.0-8+etch13.

Greetz
M.

#4
[eluser]mvdg27[/eluser]
Hi Mubsel,

You seem to be right! I removed this code block:

Code:
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();
    }
} else {
    spl_autoload_register('smartyAutoload');
}

And replaced it with:

Code:
spl_autoload_register('smartyAutoload');

And now everything works like a charm. I haven't spotted any faulty behaviour so far. Though still wondering if removing this code block won't introduce any errors in the future. Anyone an idea what this code might be for?

Michiel

#5
[eluser]mvdg27[/eluser]
Hi there .. we posted at exactly the same time Smile

You are actually saying that this is caused by a bug in CI, rather that something in Smarty?

Cheers, Michiel

#6
[eluser]Mubsel[/eluser]
Hi Michiel,

the "new" code in Smarty3 beta is using the native autoload-function(s).
1) It is adding the sysplugin-path to the php-include-path.
2) It sets the autoloader to check first for a file with php-extension and in the second run for inc-extension
3) Checks if the default-autoload function is already loaded and loads it if it is not.

Code:
spl_autoload_register('smartyAutoload');
Seems to be the fallback solution.

Greetz
M.

#7
[eluser]Mubsel[/eluser]
Nope! Looks more like a bug in php 5.2.0! Look at the link in my second post.
Maybe you are running that version.

Solution A) Update your php-version
Solution B) Hack your CI-Code
Solution C) Hack Smarty
:-)

Greetz
M.

#8
[eluser]mvdg27[/eluser]
Ah yes .. I see it now.

I'm running PHP5.2.0 yes. I guess for now I'll use my Smarty fallback solution, until I plan for a server upgrade.

Thanks for your help!

Michiel

#9
[eluser]dkf_aimar[/eluser]
Hi, I am also play with Smarty3.b5 under CI1.7.2. And I have received an error :

Code:
Fatal error: Class 'Smarty_Internal_TemplateBase' not found in /home2/fivonean/public_html/application/libraries/Smarty-3.0b5/libs/Smarty.class.php on line 110

However, it works fine on my local (Win7 + WAMP2.0i), but not working on my host (Apache version 2.2.14 (Unix) + PHP version 5.2.11).

Is there anyone can give some ideas? Thanks a lot.

Regards


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.