Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111292 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12764 invoked from network); 3 Aug 2020 05:31:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Aug 2020 05:31:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8C3AB1804E6 for ; Sun, 2 Aug 2020 21:28:40 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 2 Aug 2020 21:28:39 -0700 (PDT) Received: by mail-il1-f179.google.com with SMTP id f68so8150060ilh.12 for ; Sun, 02 Aug 2020 21:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=N6wsj/wwaQK5toS8Y/AJSLPFBLcyIIGNZGAzp8tPUXY=; b=PcTpQFJLN6fs8WNSWjBNIZNggwSOmwxdX3CXb4P50qeqqexL6AXErQ36Zg5J2TDh+G bMWRlRzz2K2QXgg5omFKFJTIdhNxxc1cixLw9kfqDOS1doaHoNtO/gO9sizETJr0dWdz G/t9ii1Zgi3P1BPbJSeXOEl1TVd0l8nfmJMuAQs/3HtWR0lc8z+oxtr1nxPh+NW92PRb vQHRY6O1Ebj3XdorrAv6bcyvfc88+EW4/3cdBgq+wK5LQZ50w6X+kMsEu11adoTbsQbx FG5xb84azDKVjRDmBrGAqRRFBIkmavz40MWpmbId/YiYeqFFcvdS0RPBmfWcas78ILF0 WxWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=N6wsj/wwaQK5toS8Y/AJSLPFBLcyIIGNZGAzp8tPUXY=; b=MWNlxnZpetPANzC0HRx4lNIW4BkBQVxssBpOAOhLb4IROfrZFHRrH2H/ffYOwJC8VQ 20n5IdJst9EaVOpBdQYIrM5YV8OSFZ7+TZf2YdmwIJ4Aq2HsntgPVys8wB0Q0NKD+dML f56hiPZoKykPpHq/ibnOGc76VD6UqVSbqV6pE+KEbHb8aHrg4x5fj0hLRcbyIaW/S/Ps cFQDEOofo+PozLCYsjhztsOB6wmyvyQc6psIwIDWAs3ogb10KUeo4io+rC6tdc5652ra CH/FOjzeS+qqSYO8qCVtsacb7cG7wXp8ybHCQ6J/8xLe9PZZiRzzBZudP/vh8zGbxbSA OOdw== X-Gm-Message-State: AOAM5317mjEqa6zqNkBOcM/eYkBOfxrVYZY2RvK/yeM9PYusytvTqfID uWF5fdnlTJkAdKBx/ATbim9Q9XZ8HwmJ/y+edjw= X-Google-Smtp-Source: ABdhPJwaitqozAu6lM9rZdAO5zGr2DTXUetyYCTy5mlxTOdPf919v/UF6HjKefFIf6x/5a93ZTr6kza2/l0OWPd4gZ4= X-Received: by 2002:a05:6e02:e89:: with SMTP id t9mr15734574ilj.292.1596428915275; Sun, 02 Aug 2020 21:28:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 3 Aug 2020 06:28:23 +0200 Message-ID: To: 3u93n3 , PHP Internals List Content-Type: multipart/alternative; boundary="000000000000677bcd05abf1929a" Subject: Re: [PHP-DEV] Feature Request: dependencies container From: ocramius@gmail.com (Marco Pivetta) --000000000000677bcd05abf1929a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Re-writing with the internals ML in CC On Mon, Aug 3, 2020, 06:16 3u93n3 wrote: > > 2. Setter injection (as well as property injection, and also the > proposed `__inject`) leads to temporal coupling smells. Explained > otherwise, your object instances are not "functioning" right after > instantiation, which makes their API more complex and reduces reliability > (they are broken until injection has happened). Please just use the > constructor: it works, and it is a simple pre-existing injection point = =F0=9F=91=8D > > Please, read the attachment. `__inject` should be called right before > `__construct`. Thus, objects are consistent. > In constructor we could use all injected dependencies. > Yes, I checked the document. The same problem applies, since you bow have an object that doesn't function anymore if not put in the context of a DIC. The design of the proposed DIC is not usable, because it proposes a singleton DIC that operates via `register_dependency_bindings(...)`, and which overloads the `new` operator. In practice, by doing this, you are adding a lot of state and complexity to the language, since a `new Foo()` call can now implicitly mean that a global dependency binding is used to determine which parameters are passed to `Foo#__inject()`, which is almost as effective as code obfuscation. In addition to that, `new Foo()` may mean different things depending on the time at which it is called, since dependencies may have been changed in between. There's absolutely nothing wrong with passing your dependencies explicitly to your constructors: it makes the dependency graph clear. You can design the same concept of dependency resolver with an AST preprocessor and the current `__construct()` semantics =F0=9F=91=8D Alternatively, you can check the gazillion pre-existing DICs out there: auryn probably doing what you want, but with much healthier structure. > --000000000000677bcd05abf1929a--