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

problem with PHP5 and class Constant

 
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
Christopher
Smarty n00b


Joined: 30 May 2005
Posts: 1

PostPosted: Mon May 30, 2005 10:57 am    Post subject: problem with PHP5 and class Constant Reply with quote

I'm using class constant with php5 (usefull to keep the code clean).
There is a problem then trying using them inside template.

Class definition:
Code:
Class Article {
  const ONLINE=0;
  const OFFLINE=1;
  var $etat=0;
}


Template:
Code:
 {if $article->etat == Article::ONLINE}online{else}offline{/if}


Smarty don't recognise this way off using a class constante, I got the error:
syntax error: unidentified token '::ONLINE'

Then I look at the code generate, Smarty have create that:
Code:
<?php if ($this->_tpl_vars['article']->'etat == Article ::ONLINE): ?>

Note the 'space' before the ::

Class constant is very usefull then writing oo code. It help keeping the code clean and ease the reading of old code. Could it be possible to resolve this issue.
Is seems that the result code work beside the Smarty Error message.

Thx for the work done. I only use Smarty now, on all my project Smile
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon May 30, 2005 3:41 pm    Post subject: Reply with quote

This is not a bug. PHP5 class constants are simply not supported in Smarty (Smarty is a PHP4 library). Furthormore, that style of constant access is not supported by Smarty either (you need to access global constants via the $smarty variable as described in the manual).

The next major release will likely address this but how and where has not been decided -- while class constants make a lot of sense for PHP5 class code, they make much less sense for a template system that is supposed to abstract application details away from the template user.
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