Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64804 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17708 invoked from network); 10 Jan 2013 07:40:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jan 2013 07:40:24 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.143 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.143 smtp143.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.143] ([67.192.241.143:49890] helo=smtp143.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7E/42-02684-3607EE05 for ; Thu, 10 Jan 2013 02:40:21 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp14.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 572D92985A1; Thu, 10 Jan 2013 02:40:15 -0500 (EST) X-Virus-Scanned: OK Received: by smtp14.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id EA7F4298042; Thu, 10 Jan 2013 02:40:14 -0500 (EST) Message-ID: <50EE705D.6020203@sugarcrm.com> Date: Wed, 09 Jan 2013 23:40:13 -0800 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Clint Priest CC: PHP internals References: <50ED4C18.3090806@zerocue.com> <9f792e7e11c481c5f4c62ce69ae216b6@mohiva.com> <50ED707E.1070503@zerocue.com> <50ED9E0E.4050100@sugarcrm.com> <50EDCE5A.4090003@zerocue.com> In-Reply-To: <50EDCE5A.4090003@zerocue.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] - "attributes" rather than "annotations" From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > In essence the example would be something along the lines of "$s must be > a string with length exactly 4 and if not, trigger_error() with the > given error message and error level. OK, I see what you mean, but it is still unclear what such construct does. At least conceptually, I do not understand what is php:Param, what is StringLength, what is the relationship between them, which code is called when and why, what are ErrorMessage= and ErrorLevel=. In C# I can understand that that declaration is completely passive and is used by some .net classes to perform their validation work. What would be performing this work in PHP? It also raises some future compatibility questions: if we would want to have named parameters for functions it'd be very awkward if we had one syntax for named parameters here and another for functions. > A similar type of thing could occur for PHP, the recent use case of > Nullable for Type Hints would be a great use of such attributes, but I'm not sure it would be the same, as type hints are supposed to be validated automatically on each call, and data annotations, of which you brought the example, do not work like that, if I understand this correctly: http://stackoverflow.com/questions/6496705/how-do-data-annotations-work >>> class a { >>> [php:Param($s) = StringLength(4, ErrorMessage='Parameter $s length >>> cannnot exceed 4.', ErrorLevel=E_USER_ERROR)] >>> public function foo($s) { ... ] >>> } -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227