Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

using registerClass with function throws Smarty Compiler err

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Jerc
Smarty Rookie


Joined: 26 Jan 2010
Posts: 30
Location: Slovenia / Ljubljana

PostPosted: Fri Oct 23, 2015 7:59 am    Post subject: using registerClass with function throws Smarty Compiler err Reply with quote

I'm not sure if this is a "Smarty Compiler: Syntax error in template" or i don't know how to var_dump a DateTime object.

Case 1 (working: entire array and item on position 0 is printed)
.php
Code:
$smarty->assign('datetime', array(new \DateTime(), new \DateTime()));

.tpl
Code:
{$datetime|var_dump}<br />
{$datetime[0]|var_dump}



Case 2 (throwing Smarty Compiler error; entire array is printed, but item on position 0 throws compiler exception):
myclass.php
Code:
namespace Test;

class MyDateTime {
    protected static $DATE = array();

    public static function init () {
        self::$DATE = array(
            new \DateTime(),
            new \DateTime()
        );
    }

    public static function getValue($constant)
    {
        return static::$DATE;
    }
}


.php
Code:

MyDateTime::init();
$smarty->registerClass('Test', 'Test\MyDateTime');

// test output
var_dump(MyDateTime::getValue('DATE')[0]);


.tpl
Code:
{Test::getValue('DATE')|var_dump}<br />
{Test::getValue('DATE')[0]|var_dump}


I tried with this combinations and i always got the Smarty compiler exception:
Code:
{(Test::getValue('DATE')[0])|var_dump}
{((Test::getValue('DATE'))[0])|var_dump}



Updated:
I tried this on Smarty version 3.1.27.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Oct 23, 2015 5:04 pm    Post subject: Reply with quote

\Test
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Oct 24, 2015 9:24 pm    Post subject: Reply with quote

Note: The Smarty template syntax is similar to but not identical with PHP.

Array index after function result is not supported.
Back to top
View user's profile Send private message
Jerc
Smarty Rookie


Joined: 26 Jan 2010
Posts: 30
Location: Slovenia / Ljubljana

PostPosted: Mon Oct 26, 2015 7:01 am    Post subject: Reply with quote

Thanks for the reply.

I'll assign variables in tpl or php and use them.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs 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