* Factory Methodパターン [#ya023155]
<?php
class Foo {
private $v1 = null;
private function __construct($options) {
$v1 = $options['v1'];
}
public static function getInstance($options) {
return new Foo($options);
}
}
** ダメ [#j7ebc293]
$obj = new Foo(array('v1' => 100));
PHP Fatal error: Call to private Foo::__construct() from invalid context in /home/yano/tmp/1.php on line 12
PHP Fatal error: Call to private Foo::__construct() from invalid context in /home/taro/tmp/1.php on line 12
** OK [#p1e0b8e8]
$obj = Foo::getInstance(array('v1' => 100));
object(Foo)#1 (1) {
["v1":"Foo":private]=>
NULL
}