infernov
Новичок
PHP Catchable fatal error
может кто подскажет, столкнулся с такой интересной ошибкой на хостинге
для краткости привожу простой пример
//--файл test.html---------------------
<html>
<body>
<script>
function ajax_do() {
var jsel = document.createElement('SCRIPT');
jsel.type = 'text/javascript';
jsel.src = 'ajax.php';
document.body.appendChild (jsel);
}
</script>
<form><input type='button' onclick='ajax_do();'></form>
</body>
</html>
//--файл ajax.php-----
<?php
include_once("class.php");
session_start();
$test = new Test();
$test->add("abc");
echo "alert('".$_SESSION['cart']."');";
?>
//--файл class.php------
<?php
class Test {
public function add($id) {
$_SESSION['cart'] .= $id;
}
}
?>
вызываем test.html жмем на кнопку первый раз, всё прекрасно работает!
жмем второй раз и в error_log получаем "PHP Catchable fatal error: Object of class Test could not be converted to string in class.php on line 4"
из-за чего такое может быть?
может кто подскажет, столкнулся с такой интересной ошибкой на хостинге
для краткости привожу простой пример
//--файл test.html---------------------
<html>
<body>
<script>
function ajax_do() {
var jsel = document.createElement('SCRIPT');
jsel.type = 'text/javascript';
jsel.src = 'ajax.php';
document.body.appendChild (jsel);
}
</script>
<form><input type='button' onclick='ajax_do();'></form>
</body>
</html>
//--файл ajax.php-----
<?php
include_once("class.php");
session_start();
$test = new Test();
$test->add("abc");
echo "alert('".$_SESSION['cart']."');";
?>
//--файл class.php------
<?php
class Test {
public function add($id) {
$_SESSION['cart'] .= $id;
}
}
?>
вызываем test.html жмем на кнопку первый раз, всё прекрасно работает!
жмем второй раз и в error_log получаем "PHP Catchable fatal error: Object of class Test could not be converted to string in class.php on line 4"
из-за чего такое может быть?
