Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* 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() fro...
** OK [#p1e0b8e8]
$obj = Foo::getInstance(array('v1' => 100));
object(Foo)#1 (1) {
["v1":"Foo":private]=>
NULL
}
終了行:
* 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() fro...
** OK [#p1e0b8e8]
$obj = Foo::getInstance(array('v1' => 100));
object(Foo)#1 (1) {
["v1":"Foo":private]=>
NULL
}
ページ名: