Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98498 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22927 invoked from network); 12 Mar 2017 09:14:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2017 09:14:22 -0000 Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain lsces.co.uk designates 185.153.204.204 as permitted sender) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 185.153.204.204 mail4.serversure.net Linux 2.6 Received: from [185.153.204.204] ([185.153.204.204:34606] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/B8-38004-B6115C85 for ; Sun, 12 Mar 2017 04:14:21 -0500 Received: (qmail 21835 invoked by uid 89); 12 Mar 2017 09:14:16 -0000 Received: by simscan 1.3.1 ppid: 21828, pid: 21831, t: 0.0431s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.62?) (lester@rainbowdigitalmedia.org.uk@81.138.11.136) by mail4.serversure.net with ESMTPA; 12 Mar 2017 09:14:16 -0000 To: PHP internals References: Message-ID: Date: Sun, 12 Mar 2017 09:14:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Type variants From: lester@lsces.co.uk (Lester Caine) On 11/03/17 06:36, Michael Vostrikov wrote: > $rectangle = new Rectangle(0, 0, 10, 10); > drawSquare($rectangle); > > When drawSquare() is called, the check 'instanceof' is performed. It calls > magic method __match(). > If __match() does not return true, it throws an exception with the data > returned: My problem here is with the reason for needing a different class for 'Square' when $rectangle->is_square() is a simple additional check on a single Rectangle class. drawSquare() seems redundant when $rectangle->draw() does the same job ... a lot of duplicate code for little gain? My problem I think is 'instanceof' is being used incorrectly here. > 'Order does not match OrderForCheckout. Reason: ...'. The class is 'Order' which in my book will be a variable list of 'LineItem' and each line item will have a status such as is_instock(). The Order status of is_shipable() flags an order that is ready for shipment which will produce an answer of yes, partial or no. Just as you don't need to change Rectangle->Square just because you want to draw a square with a set of numbers which started as a Rectangle, you don't want to change the class from Order to OrderForCheckout. The base order simple has a set of constraints which must be met before is_ready can apply and is_billable will flag if you only charge for a shipment, or take a full payment with order. LineItem has a check on 'backorder' to validate if it's allowed to add items which are out of stock. While I think I can see the logic behind describing these as different types of object I think it is the same mistake as strictly enforcing 'int' when the raw data you have is a string of numbers. And just because you know you have a number for the quantity to buy you still need to check that against the stock level and handle it differently if there is not sufficient stock. Trying to create 'type's for all the variants of the object is just wrong? int_instock, int_minorder, int_backorder, int_special_production and so on as the types of LineItem so 'instanceof' will work for you? -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk