xref: /PHP-8.0/tests/classes/inheritance.phpt (revision 7aacc705)
1--TEST--
2Classes inheritance test
3--FILE--
4<?php
5
6/* Inheritance test.  Pretty nifty if I do say so myself! */
7
8class foo {
9  public $a;
10  public $b;
11  function display() {
12    echo "This is class foo\n";
13    echo "a = ".$this->a."\n";
14    echo "b = ".$this->b."\n";
15  }
16  function mul() {
17    return $this->a*$this->b;
18  }
19};
20
21class bar extends foo {
22  public $c;
23  function display() {  /* alternative display function for class bar */
24    echo "This is class bar\n";
25    echo "a = ".$this->a."\n";
26    echo "b = ".$this->b."\n";
27    echo "c = ".$this->c."\n";
28  }
29};
30
31
32$foo1 = new foo;
33$foo1->a = 2;
34$foo1->b = 5;
35$foo1->display();
36echo $foo1->mul()."\n";
37
38echo "-----\n";
39
40$bar1 = new bar;
41$bar1->a = 4;
42$bar1->b = 3;
43$bar1->c = 12;
44$bar1->display();
45echo $bar1->mul()."\n";
46?>
47--EXPECT--
48This is class foo
49a = 2
50b = 5
5110
52-----
53This is class bar
54a = 4
55b = 3
56c = 12
5712
58