mirror of
https://github.com/php/php-src.git
synced 2024-11-29 04:46:07 +08:00
34 lines
414 B
PHP
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
|