Re: - "attributes" rather than "annotations"

From: Date: Wed, 09 Jan 2013 20:08:58 +0000
Subject: Re: - "attributes" rather than "annotations"
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
I was just looking into C# attributes at the time since I had used them in the past.

It was a loose translation to something for php from the example on this page:
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx

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.

One of the beautiful things about the C# way of attributes is that they can be user-defined, so long as they are written to the API for C# Attributes.

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 there are dozens of other uses for them, especially if implemented in a way similar to C#.

On 1/9/2013 10:42 AM, Stas Malyshev wrote:
Hi!
class a {
      [php:Param($s) = StringLength(4, ErrorMessage='Parameter $s length
cannnot exceed 4.', ErrorLevel=E_USER_ERROR)]
      public function foo($s) { ... ]
}
What this is supposed to do?
-- -Clint

Thread (31 messages)

« previous php.internals (#64784) next »