Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84676 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1220 invoked from network); 13 Mar 2015 11:54:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Mar 2015 11:54:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.179 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.179 mail-we0-f179.google.com Received: from [74.125.82.179] ([74.125.82.179:44797] helo=mail-we0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/60-32208-0EFC2055 for ; Fri, 13 Mar 2015 06:54:08 -0500 Received: by wesp10 with SMTP id p10so22701448wes.11 for ; Fri, 13 Mar 2015 04:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=8dpPBtXHDGnEAU0MDWk7TCteUrT/A4WQcBOEsPsku9A=; b=VsoRJRZJQGAdzQgmZRVp7J+KCLWUFpeQm2MMBGivPSjpQmZwfxL5hVQZmmtmVxq0Bn GLxlpQ05lkL6N1WQz86tXGnuXm0iD3YvZ2A21Ovb+YG7c4bRLBo4JPFB5jIKR5lOyMNu yzCMf/DNs+WXXI+NxSDE7fHytouvDAhvXsK4lhuKdJi8oAiyYEbyx55ieUbnBCrEIbTV T6GIeDfJ2SqIhGamGy99oPZka/MMnwd82KyQMVugijHB19MyV4mpn6Wn4tWfk84/5aQJ e2RLMpxZsRU+OX1bXjmmRY6/NQJmPMJiKzQk/h0iaDhBhOGVVdXmE4EA6sQEYz5Y9w0k 3uPw== X-Received: by 10.194.120.132 with SMTP id lc4mr98431323wjb.92.1426247645275; Fri, 13 Mar 2015 04:54:05 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id dz6sm2507307wib.0.2015.03.13.04.54.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Mar 2015 04:54:04 -0700 (PDT) Message-ID: <5502CFB4.7080406@gmail.com> Date: Fri, 13 Mar 2015 11:53:24 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: internals@lists.php.net References: <6D.2C.32765.10EC0055@pb1.pair.com> <5500D967.5040800@gmail.com> <13.69.64353.73451055@pb1.pair.com> <5501876C.3020107@gmail.com> <3D.85.42021.3E7A1055@pb1.pair.com> <5501B77D.5010800@gmail.com> <85.D1.24603.247C1055@pb1.pair.com> <5501D328.9040800@gmail.com> <98.26.24603.C9DE1055@pb1.pair.com> <5501F823.3060805@gmail.com> <55023052.40100@gmx.de> <7B.3E.24603.E83B2055@pb1.pair.com> In-Reply-To: <7B.3E.24603.E83B2055@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] static constructor From: rowan.collins@gmail.com (Rowan Collins) Johannes Ott wrote on 13/03/2015 09:53: > Am 13.03.2015 um 01:33 schrieb Christoph Becker: >> Johannes Ott wrote: >> >>> And i although see no DI or Singleton pattern to use here to get the >>> same functionality, if you want to use like Config::getHostname() and >>> not like Config::getInstance()->getHostname() which is really >>> unnecessary abstraction level for nothing in my opinion! >> It is possible, however, to add static wrapper methods to access the >> singleton's methods, like >> >> public static function getHostname() { >> return self::getInstance()->_getHostname(); >> } >> > I really do not understand why everybody here seems to try to use > Singleton where ever it is possible. Indeed Singletons are a nice Design > Pattern, but they are no universal remedy for every problem just for the > fact you can use it there as well. > > Why are in your opinion static members are not allowed to hold more > complexe datastructures then simple scalars? Complex data structures, yes (and I see the use of __static in such cases). Architectural logic gluing one class to another (as in your Logger example), no. > Please give me one valid > argument why I should double all of the functions in my code for a > static and non-static access beside the argument that I "have to" use a > Singleton. You don't need to double all the calls. In fact, the majority of your code should not even know the Singleton is there, because they should be treating it as though they have an instance. At certain key points in your code (constructors, the top of methods) you add $foo = Foo::getInstance();, then all your calls look like $foo->doBar(); That's the way I do it, anyway - treat getting the instance for a singleton like importing a variable from global scope, which is basically what it's doing. Regards, -- Rowan Collins [IMSoP]