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

Undefined variable error?
Goto page 1, 2  Next
 
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 -> General
View previous topic :: View next topic  
Author Message
legendarydrew
Smarty Rookie


Joined: 04 Feb 2010
Posts: 5

PostPosted: Wed Feb 23, 2011 3:30 pm    Post subject: Undefined variable error? Reply with quote

I've just upgraded to the latest Smarty (3.0.7) with a fresh copy, and for some reason I get the following error when Smarty comes across a variable placeholder that hasn't been assigned:

Undefined variable: args_id ~ C:\...\sysplugins\smarty_internal_data.php [ 291 ]

I'm guessing it's just a thrown notice, but nothing happens after it.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Feb 23, 2011 3:43 pm    Post subject: Reply with quote

On undefinied variables Smarty3 does drop a notice unless you did not disabled notices with $smarty->error_reporting property.

Anyway it does continue execution.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Feb 23, 2011 5:54 pm    Post subject: Reply with quote

Quote:
NOTICE for 3.0.5 release:

Smarty now follows the PHP error_reporting level by default. If PHP does not mask E_NOTICE and you try to access an unset template variable, you will now get an E_NOTICE warning. To revert to the old behavior:

$smarty->error_reporting = E_ALL & ~E_NOTICE;
Back to top
View user's profile Send private message Visit poster's website
MarkM
Smarty Rookie


Joined: 06 Jun 2011
Posts: 5

PostPosted: Mon Jun 06, 2011 5:37 am    Post subject: Reply with quote

I am having the same problem using version 3.0.8. I set the following:

$smarty->error_reporting = E_ALL & ~E_NOTICE;

where $smarty is my smarty object. This is called before make any display calls. I am doing the other initialization items before it like setting the directories and registering plugins. I also do a few assignments. Does this need to be set before doing anything else?

This is a fragment of the message in my error log:

.../smarty/sysplugins/smarty_internal_data.php (291) Undefined variable: xxx ....
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Jun 06, 2011 3:33 pm    Post subject: Reply with quote

Setting error_reporting befor you call display should be okay.

Do you have caching enabled? may be for some reasion the error messaged got stored in the cache file. Just in case empty the cache folder.
Back to top
View user's profile Send private message
MarkM
Smarty Rookie


Joined: 06 Jun 2011
Posts: 5

PostPosted: Mon Jun 06, 2011 8:57 pm    Post subject: Reply with quote

I cleared the cache and the same problem is occurring. I am using the fpm version of php if that matters. These notices appear in my web server's error log. Here is a more detailed version of the notice message:

2011-06-06 1:51:42 pm /smarty/sysplugins/smarty_internal_data.php (291) Undefined variable: xxx" while reading response header from upstream, client: IP Address, server: URL, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "URL" {I obfuscated the variable name,IP Address and URL in this example}
Back to top
View user's profile Send private message
SOSkr
Smarty n00b


Joined: 10 Sep 2011
Posts: 2

PostPosted: Sat Sep 10, 2011 2:50 pm    Post subject: Problem Reply with quote

i have the same problem, anyone could solve it?
Back to top
View user's profile Send private message
MarkM
Smarty Rookie


Joined: 06 Jun 2011
Posts: 5

PostPosted: Sat Sep 10, 2011 6:06 pm    Post subject: Reply with quote

I should also mention that I have xdebug installed. I forgot to mention that in my initial post. I know that is does get involved with PHP's error/warning/notice system
Back to top
View user's profile Send private message
SOSkr
Smarty n00b


Joined: 10 Sep 2011
Posts: 2

PostPosted: Sat Sep 10, 2011 6:34 pm    Post subject: Reply with quote

I've been testing one by one, the version of a smarty and I realized that even the version 3.0.5 this
Code:
$smarty->error_reporting = E_ALL & ~E_NOTICE;
worked, from the version 3.0.6 does not work.

Checking the logs I could see this change
Quote:
bugfix getTemplateVars() should return 'null' instead dropping E_NOTICE on an unassigned variable
in 3.0.6, I do not know what does, but maybe you can use to discover what is happening.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Sep 11, 2011 8:30 am    Post subject: Reply with quote

Are you using codeigniter? It does grab and log errors by it's own. Also xdebug or special PHP versions like fpm may effect error logging.
Back to top
View user's profile Send private message
cbj4074
Smarty Regular


Joined: 10 Nov 2011
Posts: 49

PostPosted: Thu Nov 10, 2011 4:58 pm    Post subject: Reply with quote

I have the same issue. When I upgraded to Smarty 3.0.8, this issue was introduced.

Like the others in this thread, I am configuring Smarty error reporting with the following:

Code:

$smarty->error_reporting = E_ALL & ~E_NOTICE;


I am doing this before calling $smarty->fetch() or $smarty->display().

I've seen mention of xdebug and PHP FPM, but I am using neither on the server on which this is a problem.

Curiously, I am using xdebug locally, but the problem does not occur there (it only occurs on the production server).

This is a deal-breaker for us. It seems that this problem does not occur for most, but if this thread is any indication, the problem is widespread enough to warrant further investigation on behalf of the developers.

What can I do to help?

Thank you!
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Nov 10, 2011 10:09 pm    Post subject: Reply with quote

Could it be that your server did configure error_reporting within httpd.conf by using php_admin_value?

I that case the server does not allow changing the error_reporting at script level.

Anyway it is better to handle expected undefinded variables in templates by using the default modifier or isset() conditions.
Back to top
View user's profile Send private message
cbj4074
Smarty Regular


Joined: 10 Nov 2011
Posts: 49

PostPosted: Thu Nov 10, 2011 11:04 pm    Post subject: Reply with quote

Thanks, U.Tews! You're absolutely right.

In the development environment in question, the error-reporting level is defined within the vhost's configuration file (using php_admin_value); this is to prevent developers from lowering the value and writing sloppy code as a result. It makes perfect sense that we would not be able to override that value at run-time. Again, thank you for the invaluable insight here.

Further, we'll take your advice and use the default modifier and isset() to achieve the desired result in a more sane manner.

Cheers!
Back to top
View user's profile Send private message
MarkM
Smarty Rookie


Joined: 06 Jun 2011
Posts: 5

PostPosted: Thu Nov 10, 2011 11:07 pm    Post subject: Reply with quote

I am not using Apache but nginx and I am using xdebug with php-fpm fast cgi daemon.

I completely control the server with root access (not a shared virtual environment with a 3rd party that has ultimate control). I still have these issues.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Nov 11, 2011 12:15 am    Post subject: Reply with quote

Have a look at the Log_Level parameter in php-fpm.conf.
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 -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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