mirror of
https://github.com/php/php-src.git
synced 2024-10-20 07:53:58 +00:00
36 lines
522 B
Plaintext
36 lines
522 B
Plaintext
|
--TEST--
|
||
|
ZE2 factory objects
|
||
|
--SKIPIF--
|
||
|
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
|
||
|
--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
|