xref: /PHP-7.3/tests/classes/inheritance.phpt (revision 782352c5)
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--EXPECT--
47This is class foo
48a = 2
49b = 5
5010
51-----
52This is class bar
53a = 4
54b = 3
55c = 12
5612
57