Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95035 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13353 invoked from network); 11 Aug 2016 12:50:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2016 12:50:21 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.218 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.218 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.218] ([81.169.146.218:30360] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2B/82-22587-B847CA75 for ; Thu, 11 Aug 2016 08:50:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1470919817; l=7966; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=ax1A1JbMXo1MI0F106NhZgnFwllGEbrwdmiArhIxIAM=; b=lv9RMytx5z5yJALFhPccT0IS6PJX5qqFp7KqHL+8alLtiwsiiEaE+7jlvnF8ULTeKmH Kelq6me8a3zJY/9mkzg5hB5dJY/MB5zUwIU9GEyXG3WcJbUkkiA+eeQX0skPVXn3yT4od 4PGO0y2wsrQJyy9XOTki+bjx3KYVRLvhrN0= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3o6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f49.google.com ([74.125.82.49]) by smtp.strato.de (RZmta 38.13 AUTH) with ESMTPSA id R06c1es7BCoHihO (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Thu, 11 Aug 2016 14:50:17 +0200 (CEST) Received: by mail-wm0-f49.google.com with SMTP id q128so28040585wma.1 for ; Thu, 11 Aug 2016 05:50:17 -0700 (PDT) X-Gm-Message-State: AEkoouuofWsiEw1IPNFlCciLhRPxsTgQOxnR629mNl9DWKv57C0CyQxFXRV3UbJXUn3PsTc7wS2M08Iv+AzP/g== X-Received: by 10.194.184.39 with SMTP id er7mr9488947wjc.159.1470919816928; Thu, 11 Aug 2016 05:50:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.27.206 with HTTP; Thu, 11 Aug 2016 05:50:16 -0700 (PDT) In-Reply-To: References: <10fbcb03-5de8-4d9a-da1c-7e2bf77937cb@lsces.co.uk> Date: Thu, 11 Aug 2016 14:50:16 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Lester Caine Cc: PHP Internals Content-Type: multipart/alternative; boundary=047d7ba97a102e7bb40539cb356e Subject: Re: [PHP-DEV] Simple variable handling. From: me@kelunik.com (Niklas Keller) --047d7ba97a102e7bb40539cb356e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2016-08-11 14:42 GMT+02:00 Lester Caine : > On 11/08/16 04:56, Micha=C5=82 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 caus= e > of > > throwing much more unexpected exceptions during runtime? > > Imagine you'll be passing such variable with constraint into some objec= t > > 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. > If not by using exceptions, how would you handle them if you assign such checks to variables and assign a wrong value? Regards, Niklas > 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=3Dcontact > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7ba97a102e7bb40539cb356e--