Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95034 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11705 invoked from network); 11 Aug 2016 12:42:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2016 12:42:55 -0000 Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.230 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.230 mail4-3.serversure.net Linux 2.6 Received: from [217.147.176.230] ([217.147.176.230:40790] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/32-22587-DC27CA75 for ; Thu, 11 Aug 2016 08:42:53 -0400 Received: (qmail 2676 invoked by uid 89); 11 Aug 2016 12:42:50 -0000 Received: by simscan 1.3.1 ppid: 2670, pid: 2673, t: 0.0870s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.7?) (lester@rainbowdigitalmedia.org.uk@81.138.11.136) by mail4.serversure.net with ESMTPA; 11 Aug 2016 12:42:50 -0000 To: internals@lists.php.net References: <10fbcb03-5de8-4d9a-da1c-7e2bf77937cb@lsces.co.uk> Message-ID: Date: Thu, 11 Aug 2016 13:42:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Simple variable handling. From: lester@lsces.co.uk (Lester Caine) On 11/08/16 04:56, MichaƂ Brzuchalski wrote: > You want to stick such validation at runtime at any time with variable and > throwing \TypeError at any time constraint is broken - wouldn't it cause of > throwing much more unexpected exceptions during runtime? > Imagine you'll be passing such variable with constraint into some object > who operates on it and it should expect \TypeError at any time because you > newer know what sort of constraint and optional validation callback is > sticked to variable! Now this is where the fundamental difference in styles comes in. PERSONALLY I would not be looking to throw exceptions at all. The whole point of validation is to handle any validation error ... and it is an error not an exception. We have had the discussions on annotations and currently even historic legacy systems still use docblock annotation to provide data that is not handled in the core. The new 'styles' of adding this don't really address making this area integral within the core, just as adding fancy eyecandy to flag int or string does very little to the core validation problems. setannot( $age, 'number', range(1,120) ); // Fractional Years or $age->setannot( 'number', range(1,120) ); Both make perfect sense in my style of programming PHP, along with such things as setaccess( 'public_readonly', 'no_write' ); This also comes in line with 'is_set' or 'is_valid'. if ( !is_valid( $age ) { message( $age, 'no_valid' ); } Rather than trying to capture some exception that was created out of line. In my book if you want to produce compact optimised code then you should be using C directly and the compiler optimizations. PHP needs a well structured and compact runtime engine that handles simple objects such as '$age' and every other variable using the ONE set of resident optimised code, but it seems that everybody expects the runtime process to duplicate copies of that code for every variable and then optimize each to trim elements that are not needed for that particular use of the variable? Why is it not simply a case that the table of variables simply passes a pointer to the variable code to process an operation like $age->setannot( 'number', range(1,120) ); at which point setannot( $age, 'number', range(1,120) ); makes perfect sense since $age is simply passed to the global library of code. -- 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