无法在 VSCode 中使用 xdebug 检查 $_SESSION 数组变量

问题描述 投票:0回答:0

我今天在我的 VSCode 中为 PHP 设置了 xdebug。到目前为止一切都很好,但由于某种原因,我在

$_SESSION
数组中的所有变量都显示为
null
(或观察列表中的
can not get property
)。但是我的脚本按预期工作,
$_SESSION
数组填充了正确的变量。

我什至可以看到在我开始会话时正在创建

$_SESSION
数组。例如,一个相关变量
$user_id
(在该脚本中启动会话时存在)一旦在代码中被访问,就会出现在变量列表中——但显示为
null
.

我怀疑这与我开始会话的方式有关。我是这样做的:

  1. 这是我

    debugged script
    的开始:

    // Parts Inventory Page
    $basename = basename(__FILE__);
    $title = 'Parts Inventory';
    require_once('head.html');
    
    
  2. 这是

    head.html
    的第一行:

    <?php include 'session.php'; ?>

  3. 最后,在

    session.php
    会议开始:

// Initiate session or not initiate sesstion - that is the question!

// Start session if not started yet
if (session_status() === PHP_SESSION_NONE) {
    session_set_cookie_params(0, '/', '', true, true);
    session_start();
}

// This is not index.php
if ($basename != 'index.php') {
    // User already logged in
    if (isset($_SESSION['user_id'])) {
        $user_id = $_SESSION['user_id'];
    }
    // User not logged in and not index.php, so redirect him there
    else {
        header("Location: /PartHub/index.php?redirect=1");
    }
}
// This is index.php
else {
    if (isset($_SESSION['user_id'])) {
        $user_id = $_SESSION['user_id'];
    }
    // Make them click one of the buttons by showing the modal
    else {
        if ($_GET['redirect']) {
            $show_modal = 1;
        }
    }

}
?>

这可能是 xdebug 无法访问

$_SESSION
数组变量的原因吗?同样,代码运行完美,我只想为将来设置适当的调试。

php visual-studio-code xdebug
© www.soinside.com 2019 - 2024. All rights reserved.