Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98501 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28580 invoked from network); 12 Mar 2017 09:58:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2017 09:58:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.85 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.85 mx104.easyname.com Received: from [77.244.243.85] ([77.244.243.85:55407] helo=mx104.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0D/B9-38004-CCB15C85 for ; Sun, 12 Mar 2017 04:58:36 -0500 Received: from cable-81-173-135-7.netcologne.de ([81.173.135.7] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cn0Gm-0002hN-4T; Sun, 12 Mar 2017 09:58:33 +0000 Reply-To: internals@lists.php.net References: To: Michael Vostrikov Cc: PHP Internals Message-ID: <60608cfe-5ac3-937b-9184-913f76cde82c@fleshgrinder.com> Date: Sun, 12 Mar 2017 10:58:27 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] Type variants From: php@fleshgrinder.com (Fleshgrinder) On 3/12/2017 10:36 AM, Michael Vostrikov wrote: > Now we need to write in business logic the following: > > function checkout(Order $order) > { > if (count($order->products) > 0) { > throw new SomeException1(); > } > if ($order->date === null) { > throw new SomeException2(); > } > if ($order->address === null) { > throw new SomeException3(); > } > > // checkout steps > ... > someActionWithOrderForCheckout($order); > ... > } > > function someActionWithOrderForCheckout(Order $order) > { > if (count($order->products) > 0) { > ... > } > if () > ... > } > > > Of course, we can move all checks to some function like > 'ensureOrderIsReadyForCheckout()' and call it everywhere manually. > But this is the same as call is_integer() manually instead of type hinting. > The problem you are facing is that you are dealing with an anemic domain object that does not enforce its own invariants. Properly applying OOD principles would remedy all your problems. However, you do not require new features to do that. -- Richard "Fleshgrinder" Fussenegger