Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is $_SESSION passed by reference in PHP 7?

Tags:

php

session

php-7

I am upgrading from PHP 5.6 to PHP 7 and a strange problem occurred.

    <?php
    session_start();
    $_SESSION['test'] = true;
    $var = $_SESSION;
    session_unset();
    print_r($var);

PHP 5.6 Output:

Array
(
    [test] => 1
)

PHP 7 Output:

Array
(
)

I assume this is happening because $_SESSION is passed by reference, but why?

like image 405
Daniel ghostovice Avatar asked Oct 09 '16 11:10

Daniel ghostovice


1 Answers

To conclude, it was a bug that is now fixed starting with PHP 7.0.13. Details in comments of the question.

like image 171
Mihai MATEI Avatar answered Nov 10 '22 04:11

Mihai MATEI