xref: /PHP-7.4/tests/classes/factory_001.phpt (revision a8d901a8)
1--TEST--
2ZE2 factory objects
3--FILE--
4<?php
5
6class Circle {
7	function draw() {
8		echo "Circle\n";
9	}
10}
11
12class Square {
13	function draw() {
14		print "Square\n";
15	}
16}
17
18function ShapeFactoryMethod($shape) {
19	switch ($shape) {
20		case "Circle":
21			return new Circle();
22		case "Square":
23			return new Square();
24	}
25}
26
27ShapeFactoryMethod("Circle")->draw();
28ShapeFactoryMethod("Square")->draw();
29
30?>
31--EXPECT--
32Circle
33Square
34