Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46086 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96666 invoked from network); 18 Nov 2009 17:27:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Nov 2009 17:27:11 -0000 Authentication-Results: pb1.pair.com header.from=robert@typo3.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=robert@typo3.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain typo3.org from 217.72.131.73 cause and error) X-PHP-List-Original-Sender: robert@typo3.org X-Host-Fingerprint: 217.72.131.73 mail.elios.de Linux 2.6 Received: from [217.72.131.73] ([217.72.131.73:33619] helo=mail.elios.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/1F-16241-E6E240B4 for ; Wed, 18 Nov 2009 12:27:11 -0500 Received: from [192.168.178.31] (p548CCADA.dip.t-dialin.net [84.140.202.218]) by mail.elios.de (Postfix) with ESMTP id F3B671FE83FC for ; Wed, 18 Nov 2009 18:25:20 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1077) In-Reply-To: <4B042CBB.9070701@easyflirt.com> Date: Wed, 18 Nov 2009 18:27:07 +0100 Content-Transfer-Encoding: quoted-printable Message-ID: <736E87CB-44D4-4589-865D-9A9A1DB5827C@typo3.org> References: <4B0426A9.4000806@easyflirt.com> <4B042CBB.9070701@easyflirt.com> To: internals@lists.php.net X-Mailer: Apple Mail (2.1077) Subject: Re: [PHP-DEV] RFC: Custom Factories (SPL) From: robert@typo3.org (Robert Lemke) Hi Mathieu, Am 18.11.2009 um 18:19 schrieb Mathieu Suen: > Right!! > I get confused with: > $classNamme::getInstance(); >=20 > So you can easily inject dependency: >=20 > class Foo { >=20 > protected $emailer; >=20 > public function __construct($emailClass) { > $this->emailer=3D $emailClass; > } >=20 > public function bar() { > // $email =3D new $this->emailer(); Of course not = allowed > $emailer =3D $this->emailer; > $email =3D $emailer(); > // ... > } > } Well, this won't work, because Foo surely doesn't have all the knowledge = to automatically resolve dependencies for the Email implementation. What = if Email needs some SMTP Service injected? Foo won't know. Therefore it's much better to let some specialized Object Factory to do = the task. Letting Foo instantiate an Email would be asking a car to = build its engine. Better delegate that task to a factory ... Cheers, robert