Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46105 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78693 invoked from network); 19 Nov 2009 15:07:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 15:07:32 -0000 Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.227 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:45876] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/A2-65535-43F550B4 for ; Thu, 19 Nov 2009 10:07:32 -0500 Received: by fxm27 with SMTP id 27so2557902fxm.23 for ; Thu, 19 Nov 2009 07:07:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=wlBvDP41jqtZ40oKFYnTKCBPtP2FJUXBj2hK7rMJnyY=; b=iCzzHm+34f66cQyRL3SClyrsc0+s1MY3A75JY2YZiXxD9UZc9df2nDOF7IhL3vqV2B 2FMdih8ftRa58nEY8ODrlFHWyn5US+/ndKy3OyWQuZn/Mv2Yx8MFDAmmqGNT6+oW672O nQ8eCTstrvyU7//N4/auq6eJOUz+REcTAXmcg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=QAPR0xL3/3/Crub6htidEezBP1zXgVU2onQ+k6Cs7LDK2P5tIgmSZNxYmJJS8t3kN7 4iPwzCN2HiJeLBwCDY3KxTr34LgztdMT/xPLybbN7D7ELQtdwYZjYb4Al+1488S6FXtS W/zPwlOS7wJawLbgYJl1gwoRJjXsEPv4UAn3k= Received: by 10.204.10.136 with SMTP id p8mr117642bkp.56.1258643249397; Thu, 19 Nov 2009 07:07:29 -0800 (PST) Received: from ?192.168.10.112? ([82.208.177.66]) by mx.google.com with ESMTPS id 15sm162859bwz.8.2009.11.19.07.07.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 19 Nov 2009 07:07:28 -0800 (PST) Message-ID: <4B055F2F.2070802@gmail.com> Date: Thu, 19 Nov 2009 17:07:27 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.4pre) Gecko/20090915 Thunderbird/3.0b4 MIME-Version: 1.0 To: Mathieu Suen CC: internals@lists.php.net References: <4B0426A9.4000806@easyflirt.com> <4B042CBB.9070701@easyflirt.com> In-Reply-To: <4B042CBB.9070701@easyflirt.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Custom Factories (SPL) From: ionut.g.stan@gmail.com ("Ionut G. Stan") One could just as well pass an instance of Emailer to the constructor. It's the same thing, except that it's less code (and it's easier to understand in my opinion). It's a basic application of the Law of Demeter. On 11/18/2009 7:19 PM, Mathieu Suen wrote: > > Right!! > I get confused with: > $classNamme::getInstance(); > > So you can easily inject dependency: > > class Foo { > > protected $emailer; > > public function __construct($emailClass) { > $this->emailer= $emailClass; > } > > public function bar() { > // $email = new $this->emailer(); Of course not allowed > $emailer = $this->emailer; > $email = $emailer(); > // ... > } > } > -- Mathieu Suen -- Ionut G. Stan I'm under construction | http://blog.igstan.ro/