xref: /PHP-7.4/tests/lang/bug21961.phpt (revision a8d901a8)
1--TEST--
2Bug #21961 (get_parent_class() segfault)
3--FILE--
4<?php
5
6class man
7{
8	public $name, $bars;
9	function __construct()
10	{
11		$this->name = 'Mr. X';
12		$this->bars = array();
13	}
14
15	function getdrunk($where)
16	{
17		$this->bars[] = new bar($where);
18	}
19
20	function getName()
21	{
22		return $this->name;
23	}
24}
25
26class bar extends man
27{
28	public $name;
29
30	function __construct($w)
31	{
32		$this->name = $w;
33	}
34
35	function getName()
36	{
37		return $this->name;
38	}
39
40	function whosdrunk()
41	{
42		$who = get_parent_class($this);
43		if($who == NULL)
44		{
45			return 'nobody';
46		}
47		return eval("return ".$who.'::getName();');
48	}
49}
50
51$x = new man;
52$x->getdrunk('The old Tavern');
53var_dump($x->bars[0]->whosdrunk());
54?>
55--EXPECT--
56string(14) "The old Tavern"
57