<?php
 class Foo {
     private $v1 = null;
     private function __construct($options) {
         $v1 = $options['v1'];
     }
     public static function getInstance($options) {
         return new Foo($options);
     }
 }

ダメ

 $obj = new Foo(array('vi' => 100));
 PHP Fatal error:  Call to private Foo::__construct() from invalid context in /home/yano/tmp/1.php on line 12

OK

 $obj =  Foo::getInstance(array('v1' => 100));
 object(Foo)#1 (1) {
  ["v1":"Foo":private]=>
  NULL
 }

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS