Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92953 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89734 invoked from network); 29 Apr 2016 17:02:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 17:02:33 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wm0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:37756] helo=mail-wm0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A4/C1-26386-8A393275 for ; Fri, 29 Apr 2016 13:02:33 -0400 Received: by mail-wm0-f48.google.com with SMTP id a17so46419083wme.0 for ; Fri, 29 Apr 2016 10:02:32 -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=KG8mvp02aULZgw/nlYUAz+0QLJSnxG7oxQvO0zlrrQA=; b=b2j0RbtSP43RCTfsBT+3rLYN9NaG+YJGLBjadJhtH46nZQm4hGC0OAnrVQRXYZmQSU qxRPNf8xYhVB2KTSFZfxEPb6l2KdyDtesPFzwgbw32AIfB3I2M8KoTF0JogBTcfsjyRK y5aWVMJnqPmSStYB4KlRoEXCmgybkbUmx8VFt1drfV4PgtQSFIkxIhmgT0EqEQw/QqDY 5DE6gYfEwmoMMN6tlW8WcCCpDS3jbnAAlOYaFJWJIqi9cnFduQ2VcByNulzl0VZJ6g8h pSdP9xUOJN6XYJMHNP/oVOb9z2ybrf8JR9rad722kVk6JJxAIeOK52/oqZLpzbOqSZFJ gT+g== 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=KG8mvp02aULZgw/nlYUAz+0QLJSnxG7oxQvO0zlrrQA=; b=T4yDVqk8XgatfnacGY1pd2Ddj78CZp1XZ+ysM0Z9mm0pVdo8DPDIjryKsmkLRaV31O HkdHLG1eMvTIPPEW+xbkpaGMxHg2McC5VsOHtYUpBUr3xsUeoGZggjYKNNT45ODsUbiC 5Sz9tH3+Wmng5/mXkqd+55WxMGcuxL/yZaKcqXp1JQslYaNDAytbLGJh+DJykG7jMFRy mKB7p3EZpsvQB5kwEZfJXA5T4yDBT9wXby9Ccb3z9MLOBwzDIeSrhf5ckImtKbhzm4aT A6vvKYfcr5Em1PjQXrtWllwVSZRj9D0u5BzZ4VjWTrLW2nu/lsWp88xL99oyadfpCCgd lz4A== X-Gm-Message-State: AOPr4FVzOFfUmbKpjxTc3H9Rmj4rGUkwUwg3E6YL0Mh29abNInYbrO7fKdaVHUVcZ0oshQ== X-Received: by 10.194.115.8 with SMTP id jk8mr23244190wjb.142.1461949350076; Fri, 29 Apr 2016 10:02:30 -0700 (PDT) Received: from [192.168.0.82] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id r5sm4106631wjy.37.2016.04.29.10.02.29 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Apr 2016 10:02:29 -0700 (PDT) To: internals@lists.php.net References: <5720A6B4.4000307@lsces.co.uk> <5721B9DD.3050300@lsces.co.uk> <57231ADD.9040006@lsces.co.uk> <572326A3.7000809@lsces.co.uk> <57234D3D.1070602@lsces.co.uk> <79c9df57-ee45-f415-3172-95f8229bbece@gmail.com> <57235F20.5080707@lsces.co.uk> <43b9c67f-3ec7-bacc-2608-552abbd1a3fa@gmail.com> <57237B36.1070301@lsces.co.uk> <0d71618b-2ffa-7273-f9b9-aeabc35f4211@gmail.com> <572390DC.1020108@lsces.co.uk> Message-ID: <6b18ff8b-586d-8e97-2e02-ec1db82cefda@gmail.com> Date: Fri, 29 Apr 2016 18:00:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <572390DC.1020108@lsces.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PHP Attributes -> docBloc alternatives ... From: rowan.collins@gmail.com (Rowan Collins) Lester Caine wrote on 29/04/2016 17:50: > On 29/04/16 16:42, Rowan Collins wrote: >> function foo($a) { >> if ( $a < 42 ) { throw new Exception; } // Must not reach The Answer >> ... >> } >> >> vs >> >> <> // Must not reach The Answer >> function foo($a) { ... } > The first version is my current code base, although it's unlikely to > throw an exception, more likely to have already validated the data > before using it so the check is redundant as it is already in the code > to handle the problem data. But in the second example just where does > the error redirect traffic? At least with in-line checks you control > flow ... A good question. As such, the annotation doesn't execute any code in the current proposal, it just allows tools to inspect it, so the answer is "anywhere the tool manages to inject the assertion code", I guess. > but just how do you add a range? Does that need different > 'test' elements? <> is just an example. It might be <> or <0, 'max'=>42])>> or whatever you / the library author wanted it to be. None of this is going to be baked into the language. > My main target here is to add a reliable mechanism to allow every > variable to have it's own validation attributes. The only current route > is as php-annotations nicely provided and which dovetails nicely into > the existing documentation process. Indeed, the fact that you can add the attributes in advance is a nice feature of the annotations-in-docblock syntax. However, the disadvantages of that syntax have been discussed elsewhere. Like many things in life, it's a tradeoff. > I've no problem with an alternate annotation method ... as long as in > PHP7 it is optional ... Absolutely. Nobody is going to force you to use this syntax, unless you want to use some library whose author is really keen on it and doesn't provide any other method of doing something. > but I don't think this 'in-line' approach is > ACTUALLY the right long term solution to data validation. You said just now that adding the validation to the docblocks does appeal to you. At the end of the day, this is just another syntax for doing the same thing; but a more well-defined, easier-to-parse syntax, with no baggage of existing usage which it has to be compatible with. If it's not the right tool for your use case, that's fine too; maybe it's the right tool for someone else's use case, though. Regards, -- Rowan Collins [IMSoP]