xref: /PHP-5.6/tests/lang/bug22231.phpt (revision d3e50265)
1--TEST--
2Bug #22231 (segfault when returning a global variable by reference)
3--INI--
4error_reporting=E_ALL | E_DEPRECATED
5--FILE--
6<?php
7class foo {
8    public $fubar = 'fubar';
9}
10
11function &foo(){
12    $GLOBALS['foo'] = &new foo();
13    return $GLOBALS['foo'];
14}
15$bar = &foo();
16var_dump($bar);
17var_dump($bar->fubar);
18unset($bar);
19$bar = &foo();
20var_dump($bar->fubar);
21
22$foo = &foo();
23var_dump($foo);
24var_dump($foo->fubar);
25unset($foo);
26$foo = &foo();
27var_dump($foo->fubar);
28?>
29--EXPECTF--
30Deprecated: Assigning the return value of new by reference is deprecated in %s on line %d
31object(foo)#%d (1) {
32  ["fubar"]=>
33  string(5) "fubar"
34}
35string(5) "fubar"
36string(5) "fubar"
37object(foo)#%d (1) {
38  ["fubar"]=>
39  string(5) "fubar"
40}
41string(5) "fubar"
42string(5) "fubar"
43