我会保持这个简单。为什么在我的PHP脚本的顶部调用session_start()
,我得到这个输出在底部:session_start()导致致命错误
Fatal error: Exception thrown without a stack frame in Unknown on line 0
这是怎么回事?
编辑:一些进一步的细节,因为我已经进一步隔离了问题。
index.php
(节选):
<?php
session_start();
require_once('inc/database.php');
require_once('inc/gallery.php');
...
database.php
:
<?php
try {
$dsn = 'mysql:host=localhost;dbname=tees_db';
$pdo = new PDO($dsn, '[username removed]', '[password removed]');
}
catch (PDOException $e) {
header('HTTP/1.1 503 Service Unavailable');
die('There was an error connecting to the database.');
}
gallery.php
(节选):
<?php
class Gallery {
private $pdo;
public function __construct() {
global $args, $pdo, $request;
$this->pdo = $pdo;
}
...
}
$gallery = new Gallery();
这个问题是在Gallery
上课的时候我尝试和分配全球$pdo
作为类属性的变量。为什么这会在$pdo
只是一个PDO实例时导致致命错误?
编辑2:我发现关闭我的浏览器并重新启动(杀死会话)会抑制错误。错误仅在调用inc/confirm.php
时触发。
inc/confirm.php
是一个用于超过18确认的脚本。内容是微乎其微的:
session_start();
if (isset($_GET['mod'])) {
$mod = $_GET['mod'];
$_SESSION[$mod] = '1';
}
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
正如你所看到的,只是保存$_SESSION
阵列中的一个关键和重定向回到原来的页面。那里没有关于异常或类的构造函数。
http://bugs.php.net/bug.php?id=33598?你确定它的session_start()? – n00b 2011-03-09 14:46:28
我没有'__destruct'方法,更不用说抛出一个异常了;我通过删除它将它隔离到'session_start()'调用中,这也抑制了错误。 – 2011-03-09 15:00:48
但如果session_start失败,它会在页面顶部显示错误.... – n00b 2011-03-09 15:12:21