xref: /PHP-8.2/ext/session/tests/006.phpt (revision b5a14e6c)
1--TEST--
2correct instantiation of references between variables in sessions
3--EXTENSIONS--
4session
5--SKIPIF--
6<?php include('skipif.inc'); ?>
7--INI--
8session.use_cookies=0
9session.use_strict_mode=0
10session.cache_limiter=
11session.serialize_handler=php
12session.save_handler=files
13--FILE--
14<?php
15error_reporting(E_ALL);
16ob_start();
17
18session_id("test006");
19session_start();
20
21class a {
22    public $test = "hallo";
23}
24
25class b {
26    public $a;
27    function __construct(&$a) {
28        $this->a = &$a;
29    }
30}
31
32$a = new a();
33$b = new b($a);
34
35echo "original values:\n";
36var_dump($a,$b);
37
38$_SESSION["a"] = $a;
39$_SESSION["b"] = $b;
40session_write_close();
41
42unset($_SESSION["a"], $_SESSION["b"]);
43
44session_start();
45
46echo "values after session:\n";
47var_dump($a,$b);
48
49session_destroy();
50?>
51--EXPECTF--
52original values:
53object(a)#%d (1) {
54  ["test"]=>
55  string(5) "hallo"
56}
57object(b)#%d (1) {
58  ["a"]=>
59  &object(a)#%d (1) {
60    ["test"]=>
61    string(5) "hallo"
62  }
63}
64values after session:
65object(a)#%d (1) {
66  ["test"]=>
67  string(5) "hallo"
68}
69object(b)#%d (1) {
70  ["a"]=>
71  &object(a)#%d (1) {
72    ["test"]=>
73    string(5) "hallo"
74  }
75}
76