Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95037 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19639 invoked from network); 11 Aug 2016 13:53:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2016 13:53:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:35440] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/A3-22587-E638CA75 for ; Thu, 11 Aug 2016 09:53:50 -0400 Received: by mail-wm0-f53.google.com with SMTP id f65so1628409wmi.0 for ; Thu, 11 Aug 2016 06:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=+K1WxSgEZ7KKlEiw8mpd+5Pgt1BuZ93m3QObUKK5h4M=; b=AzA5MOgciMJn8ic6oE6OgRX3X+quWM2cyCKL8VXBBVBHuv3SaQjPafnwfC1ER1rUqt bnu0E5X/bx1m2uTtRC/u/oND25MnmZNIzh75bbas7IR2oTOyAvEuTE2qsrb4tYlP4/t1 tNY1Jj7/GLrPC6OHDPyYZRRRiHoQHoeXxGm5PQ2IG1ZFqqOPXvIyUYu+WH/teetw0cFA YQdQcyJw7fDZmhb9w2+g/zuBQSjA/2qqK5IyCEs7Hw4khqf/vBVSdMO735QduWirQ+bb l9/+SxuyHG8MbBNIEHDTvnaSw+2xWxXshEspiBhTiEzIc6GFgMSbymHxPgOw42UhcCdE HwtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=+K1WxSgEZ7KKlEiw8mpd+5Pgt1BuZ93m3QObUKK5h4M=; b=R+obdWMuHUMABW5THzl5ZJoUJ8KpeOEhonIjkejgBzDBVd0WIZVZHL1sadc/Brk59V QwwE5QsD7iDROj8JWomv5ooHXHJb/R5RFvLdDORRUKtHvpq2GC0Ur4WFPXMDE7r9mRtG JC9eF4Wlhemtak22o2eDpSL8qd6IsJXbGekiTX6PO4psulEz97wBfjDQ69PGoTmKPBkp dv1VGdQUWYkTmA4TyZKnrLZlDsAncnNpBJepvZVeVfUSJaZ3dqdmMAOi2Sv/G9StRvnE uL9HKubEeiUeMK7HpxSJFcYN6MHUZ8nLQh94bwlrprjJcmHug37KHnYqSUKeQHPTqHjP vDLw== X-Gm-Message-State: AEkooutCP3IxYnNPFkWQimDBsVS8OjPSf/CM5u5uF7/8ZgVzCjSxTreP48ZbmeaPAndoSg== X-Received: by 10.28.185.202 with SMTP id j193mr9696918wmf.78.1470923626429; Thu, 11 Aug 2016 06:53:46 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id n2sm2855709wjd.1.2016.08.11.06.53.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 06:53:45 -0700 (PDT) To: internals@lists.php.net References: <10fbcb03-5de8-4d9a-da1c-7e2bf77937cb@lsces.co.uk> Message-ID: <5657afc7-7569-5fc4-4a5a-27ed786c4fa5@gmail.com> Date: Thu, 11 Aug 2016 14:51:18 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Simple variable handling. From: rowan.collins@gmail.com (Rowan Collins) On 11/08/16 13:50, Niklas Keller wrote: >> > If not by using exceptions, how would you handle them if you assign such >> > checks to variables and assign a wrong value? On 11/08/2016 14:29, Lester Caine wrote: > if ( !$age->set( $result_set['age'] ) ) { // handle error } > else { // next step } So, cutting out the commentary about styles of coding, the answer to Niklas's question is "I would replace the assignment with a function or method that returned success based on validation result"? To combine some of your examples: // Set up the constraints: $age->setannot( 'number', range(1,120) ); // Later: $valid = $age->set( 'not a number' ); // or: $age = $result_set['age']; $valid = $age->is_valid(); This would result in $valid being false, but $age presumably still being the string 'not a number'? Or perhaps still being null, as though the assignment hadn't happened? It seems like it would be more useful if the user didn't have to remember to call is_valid() on each variable before using it. That means having either the write operation, or subsequent read operations "fail" in some way. $age_at_next_birthday = $age + 1; // reads from $age; is $age valid? Throwing exceptions is a way of making operations like this "fail", rather than propogating the bad data to other parts of the program. Does this look like the kind of thing you were imagining? Regards, -- Rowan Collins [IMSoP]