Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105343 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65497 invoked from network); 23 Apr 2019 08:58:17 -0000 Received: from unknown (HELO mail-pg1-f182.google.com) (209.85.215.182) by pb1.pair.com with SMTP; 23 Apr 2019 08:58:17 -0000 Received: by mail-pg1-f182.google.com with SMTP id 85so7031575pgc.3 for ; Mon, 22 Apr 2019 22:58:36 -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=oFs8Sw3YXf7AMhWhdGEq35IPyK3gzayXdO5p+SXmEwo=; b=MNhqCwEjuc4bLH2iYvlSDbprLwbRuiscvKYqrqO0a7qN6udv1LAqPkkFrpVgKvSmhK IVDvjXraqSSKZ/jXhqWWHwui81Kb+yCtK1mavD1Dd6e03hFGePcY+yzGJoYBIQIRYRNI 8q8bSPEH2CSYLlLNaUUB8gsLuaCFGK0nVSVWvAg6EkkY2rT8MB9E+4mtdcoIBeQrvMbK WF3Td4e2lbOs9ue7nIoc6Xq7jZ0tvfw38IH1d/5WmVDKkYK3I6JUpBS9oYR5Fk4+19ok 6oVW6jGahKuli/wCtzJuxvwergbcdL3bF09vChOnvQCCe6crLhlHNB+0u+XLoCiRZVVn cm5Q== 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=oFs8Sw3YXf7AMhWhdGEq35IPyK3gzayXdO5p+SXmEwo=; b=FKf4AVU3DBjlqVK8QBMdLkQAXX7kY9ljsbuK5NmS+MI7sTb52zSm/JQPBX2HaldQgH DBzR67sW9RXVu/JQb1X7h9ZETvyvge0evcA0okLfpJLtkV1+DnmTn0pYiRUdxwQgXfe3 74rPr91Y3r4wHTNqIggwtdFMfngxpawq9W5lLsQEZvmF4tAj/RueK4TxDX93p+WuvBx8 HTUkCEQRs46Q6qMJxcLuKJKcIjyl6/jHKrP2kGzdduks0QSEiFaykfSeW/KOGMXVOyiA Z7CXQ+ypHF3gfn5sXdXGZV3YoyBZF3PIlj/S64w1xtlutmo5/jp47a+Ai/usmgYDl5ka PD/A== X-Gm-Message-State: APjAAAVq9nZdJKO6CRjzzEpOEiW4wx7HS6XhCzor9EqB4HdlG3SEbn5/ w8lMLmYAesx5RIixl7R+huW1uH7FDRx0MH5XLaybtFC9 X-Google-Smtp-Source: APXvYqwm1OYJ0D1c9PGi8jecu4xUmGufLlbxfd8pXC8HXeyvfT2OjD+fMEogPXbwz6GLqXKvW+y1JOd23OkVkepOs3Y= X-Received: by 2002:a05:6a00:c1:: with SMTP id e1mr24509768pfj.143.1555999115672; Mon, 22 Apr 2019 22:58:35 -0700 (PDT) MIME-Version: 1.0 References: <899de214-607e-9ad8-80cb-eeda5adf8ee6@php.net> In-Reply-To: <899de214-607e-9ad8-80cb-eeda5adf8ee6@php.net> Date: Mon, 22 Apr 2019 22:58:28 -0700 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000008f80f205872c46f6" Subject: Re: [PHP-DEV] Object Type Casting Reloaded From: mo.mu.wss@gmail.com ("M. W. Moe") --0000000000008f80f205872c46f6 Content-Type: text/plain; charset="UTF-8" Hello, Sebastian yes; interface or abstract have been somehow created for that purpose; even if I find people abusing of those constructs; now if your container is generalized and represents dynamic data; for instance like a Message class it could hold dynamic data types; let say: // abstract public offsetGet ( mixed $offset ) : mixed $service = $diContainer['email.service'] of ?EmailService; // else throw TypeError(this type instead of null or EmailService) On Mon, Apr 22, 2019 at 10:07 PM Sebastian Bergmann wrote: > Am 22.04.2019 um 23:47 schrieb Benjamin Morel: > > These combine into a third advantage: readability. Today's equivalent of > > the above one-liner could be: > > > > /** @var EmailService $service */ > > $service = $diContainer->get('email.service'); > > if (! $service instanceof EmailService) { > > throw new TypeError('Expected instance of EmailService, ...'); > > } > > Today's equivalent is, at least for me, is this one-liner: > > assert($service instanceof EmailService); > > This way the IDE knows what type $service is supposed to be and there will > be an exception at runtime (given the appropriate configuration) when this > is not the case. > > Personally, I prefer hand-written factories that have an explicit > createEmailService() method with a :EmailService return type declaration, > for example, over the implicitness of a dependency injection container as > the latter disguises and obscures dependencies. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --0000000000008f80f205872c46f6--