php-src/tests/classes/factory_001.phpt
2017-01-30 22:50:25 +01:00

34 lines
414 B
PHP

--TEST--
ZE2 factory objects
--FILE--
<?php
class Circle {
function draw() {
echo "Circle\n";
}
}
class Square {
function draw() {
print "Square\n";
}
}
function ShapeFactoryMethod($shape) {
switch ($shape) {
case "Circle":
return new Circle();
case "Square":
return new Square();
}
}
ShapeFactoryMethod("Circle")->draw();
ShapeFactoryMethod("Square")->draw();
?>
--EXPECT--
Circle
Square