So, I’m having this weird error: Catchable fatal error: Object of class Template_Standard could not be converted to string in C:\wamp\www\game\template\standard\index.php on line 23
It’s basicly made up of these two files:
template_standard.php (functions file):
<?php
if (!defined('INCLUDED')) exit;
class Template_Standard
{
public function print_login_text ()
{
global $user_functions, $path;
if ($user_functions -> is_logged_in ())
{
return '<p>' . WELCOME_BACK . $_SESSION['username'] . '</p>';
}
else
{
return '<div id="login_form">
<form action="' . $path . 'login" method="post">
<p>
<input type="text" name="name"/> ' . NAME . '<br/>
<input type="password" name="pass"/> ' . PASSWORD . '
</p>
<p><input type="submit" value="' . LOG_IN . '" class="button"/></p>
<p><a href="' . $path . 'register" onclick="get_register();return false">' . REGISTER . '</a></p>
</form>
</div>';
}
}
public function print_menu ()
{
global $path;
$html = '<ul id="menu">';
$html .= '<li><a href="' . $path . '"><img src="' . $path . 'media/menu/home.png" width="100" height="35"/></a></li>';
$html .= '<li><a href="' . $path . 'register"><img src="' . $path . 'media/menu/register.png" width="100" height="35"/></a></li>';
$html .= '</ul>';
return $html;
}
}
?>
And the template file:
<?php
if (!defined('INCLUDED')) exit;
require '././functions/template_standard.php';
$template = new Template_Standard();
$register_form = '<form action="' . $path . 'register" method="post">\\
<p>\\
<input type="text" name="name"/> ' . NAME . '<br/>\\
<input type="password" name="pass"/> ' . PASSWORD . '<br/>\\
<input type="password" name="pass2"/> ' . PASSWORD_AGAIN . '<br/>\\
<input type="text" name="email"/> ' . EMAIL . '<br/>\\
</p>\\
<p><input type="submit" value="' . REGISTER . '" class="button"/></p>\\
</form>';
$head .= <<<HTML
<link href="{$path}template/$template/style.css" rel="stylesheet" type="text/css"></link>
<!--[if lt IE 9]><style type="text/css">#content{border:1px solid #333;}</style><![endif]-->
<script type="text/javascript">
function get_register ()
{
var speed = 'fast';
var html = '$register_form'; // Error here
$('#login_form').fadeOut(speed, function(){
$('#login_form').html(html).fadeIn(speed);
});
return false;
}
$(document).ready(function(){
if (screen.height < 768) {
$('#footer').hide();
} // Fourth error, and so on
}); // Third error here
</script> // If I remove the place with the first error, the second is here ...
HTML;
$body_start .= '<div id="content"><a href="' . $path . '"><div id="header"><img src="' . $path . 'media/header/logo.jpg" width="600" height="150"/></div></a><div id="menu-container">' . $template -> print_menu () . '</div><br style="clea:left"/><div id="content-left">';
$body_end .= '</div><div id="content-right">' . $template -> print_login_text() . '</div></div><div id="footer"><div style="float:right;text-align:right">Lorem ipsum ...</div>Copyright © 2012 Jacob<br/>All rights reserved</div>';
?>
The thing is, if I remove the line with the error, it’ll just throw an error at another line inside the HTML things. Only way to resolve it is to remove everything in it.
Also, it works good if I have the functions directly in the template file.
You use the
$templatevariable as a string:So PHP will try to convert the object to a string but it doesn’t find a
__toString()method inside your class!