Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Fatal error: Call to a member function assign()

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


Joined: 01 Nov 2011
Posts: 4

PostPosted: Tue Nov 01, 2011 4:37 am    Post subject: Fatal error: Call to a member function assign() Reply with quote

Hello,

every here and then I get an error
Quote:
Fatal error: Call to a member function assign() on a non-object in ...


I did not change ANY code. If I press F5 on my Browser the error is gone.

1. Whats up with that?
2. How can I avoid it with try catch or something?

I try this solution, but it doenst work:
Code:
if (!isset($smarty)) {
  include('Smarty.class.php');
  $smarty = new Smarty;
}
$smarty->assign("name",$_SESSION['MyName']);
Back to top
View user's profile Send private message
ema
Smarty n00b


Joined: 01 Nov 2011
Posts: 4

PostPosted: Wed Nov 02, 2011 12:24 pm    Post subject: Reply with quote

...any idea at all?

Even try catch doesn't work at all. Confused
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 537

PostPosted: Wed Nov 02, 2011 12:54 pm    Post subject: Reply with quote

ema wrote:
...any idea at all?

Even try catch doesn't work at all. Confused


That's not how try/catch works. Try/catch only works on exceptions.

You just have to make sure you have an initialized smarty object that you are calling assign() on. It should be initialized with template dir etc set.

If you do not, then there is a programming error in your code.
Back to top
View user's profile Send private message
ema
Smarty n00b


Joined: 01 Nov 2011
Posts: 4

PostPosted: Wed Nov 02, 2011 1:22 pm    Post subject: Reply with quote

For me (and I am not a root admin) it looks like a problem with MEMCACHE. We are using two servers with vanish on top.

Maybe there is a logical error with the code?

How can I test, that $tpl->assign is working, because it does in 99,8% But in the error_log I see
Quote:
PHP Fatal error: Call to a member function assign() on a non-object in /var/www/some/path/myfile.php


This does not help at all and I don't know why:
Code:
if (!isset($smarty)) {
  include('Smarty.class.php');
  $smarty = new Smarty;
}
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 537

PostPosted: Wed Nov 02, 2011 1:46 pm    Post subject: Reply with quote

ema wrote:
For me (and I am not a root admin) it looks like a problem with MEMCACHE. We are using two servers with vanish on top.

Maybe there is a logical error with the code?

How can I test, that $tpl->assign is working, because it does in 99,8% But in the error_log I see
Quote:
PHP Fatal error: Call to a member function assign() on a non-object in /var/www/some/path/myfile.php


This does not help at all and I don't know why:
Code:
if (!isset($smarty)) {
  include('Smarty.class.php');
  $smarty = new Smarty;
}



1) That would get rid of the error, but would just cause other problems because the smarty object wouldn't be initialized properly and/or the smarty library was already included.

2) The variable $smarty could have any non-object in it. Perhaps some one did something like $smarty = <some weird value>; somewhere and it overwrote the smarty object. Perhaps it was not initialized properly. It's difficult to tell.

To help diagnose the problem, I would add this before the line where the error occurs:

Code:


if (!is_object($smarty))
{
   mail('YOUR EMAIL ADDRESS HERE', 'tracing smarty error', "In ".__FILE__." line: ".__LINE__." \$smarty = ".var_export($smarty, 1).  "\nhttp://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}\n\nReferrer: {$_SERVER['HTTP_REFERER']}\n\nClient: {$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}".' backtrace is: '.print_r(debug_backtrace(), 1).' request is '.print_r($_REQUEST, 1));

}



Change the email to your email address.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Nov 02, 2011 3:56 pm    Post subject: Reply with quote

Quote:
How can I test, that $tpl->assign is working, because it does in 99,8%


Do you have the problem with $smarty->assign (..) or $tpl->assign(..) as mentioned in some of your latest posts?

May be $tpl is not set up to an template object?
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