Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Undefined index accessing undefined array item in Smarty 3

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
strikernl
Smarty n00b


Joined: 07 Dec 2010
Posts: 2

PostPosted: Tue Dec 07, 2010 12:43 pm    Post subject: Undefined index accessing undefined array item in Smarty 3 Reply with quote

In smarty 2 this was 'valid', at least it didn't spawn any notices, even on error_reporting(E_ALL), with the links key not existing:

Code:
{if $gallery.links.$imagefile.url}
   do something if that var is set and not null
{/if}


Now in smarty 3 this gives me

Code:
Notice:  Undefined index: links in [snip]templates/templates_c/be7b4e921596138e5e068096ec3476dcd65020fd.file.foo.tpl.php on line 39


Unless I wrap that {if} in isset(), which is something I prefer not do, for template 'cleanness' reasons. The point of smarty is not having to do all of the strict checking with isset() and empty() and is_array() that you have already done in PHP, right? Setting smarty 'internal' error reporting to E_ALL & ~E_NOTICE is also not really an option I like.

Is there any chance this is a bug that will be fixed, or is this just the new behaviour? Could it be made into an option?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Dec 07, 2010 1:42 pm    Post subject: Reply with quote

This is an intended change. Smarty2 and the early Smarty3 versions did always turn E_NOTICE off. This was against the coding standards in many organizations as other coding errors for example in plugins might not be detected.

With the error_reporting property you have now full control about Smarty's error reporting behaviour.
Back to top
View user's profile Send private message
strikernl
Smarty n00b


Joined: 07 Dec 2010
Posts: 2

PostPosted: Tue Dec 07, 2010 1:46 pm    Post subject: Reply with quote

Is it not possible to wrap such calls in isset() in the compiled template automatically?

The thing is, there are some notices I _do_ want to get, such as calls to non-existent Smarty functions (for instance, I am migrating this from Smarty 2, and I want to rewrite everything to Smarty 3 as I go, not in one effort. So calls to register_function for instance _should_ give a notice).
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Dec 07, 2010 3:43 pm    Post subject: Reply with quote

That's why you can set up $smarty->error_reporting. It's setting is used just for the processing time of the template itself.

With $smarty->error_reporting = E_ALL & ~E_NOTICE you get exactly the old behaviour.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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