Am 14.09.2010 22:12, schrieb Stas Malyshev:
> I think we _already_ have metadata in PHP, albeit done through
> phpdocs. So the question is kind of moot :) We should see if it's
> enough for us or we want to add/change/extend it and if so, how.
>

Hi,

in my mind there is a big mistake when using annotations in PHPDoc comments.

As example let as use a JSR 303 - Bean Validator like Hibernate
Validator for PHP.

namespace my\project\models\dto;

class User {

    /**
     * @com\jsr303\validator\constraints\NotNull
     * @com\jsr303\validator\constraints\Integer
     */
    public $id;

    /**
     * @com\jsr303\validator\constraints\NotNull
     * @com\jsr303\validator\constraints\Regexp('/[a-z]*/i')
     * @com\jsr303\validator\constraints\MinLength(2)
     * @com\jsr303\validator\constraints\MaxLength(255)
     */
    public $name;

    /**
     * @com\jsr303\validator\constraints\NotNull
     * @my\project\validator\constraints\Zipcode
     */
    public $zipcode;
}

It is possible to use this type of annotations but it is impracticable.
An other problem is that every framework use its one annotation syntax.
So it makes the framework end user more confusing as using a clear
unique syntax.

I think the PHP way should be as in the next example.

namespace my\project\models\dto;

use com\jsr303\validator\constraints\NotNull;
use com\jsr303\validator\constraints\Integer;
use com\jsr303\validator\constraints\Regexp;
use com\jsr303\validator\constraints\MinLength;
use com\jsr303\validator\constraints\MaxLength;
use my\project\validator\constraints\Zipcode;

class User {

    [NotNull]
    [Integer]
    public $id;

    [NotNull]
    [Regexp('/[a-z]*/i')]
    [MinLength(2)]
    [MaxLength(255)]
    public $name;

    [NotNull]
    [Zipcode]
    public $zipcode;
}

With this out of the box PHP annotations it makes it possible to create
powerful frameworks which can used by a great range of developers
without learning a new syntax for it. Pleas do not argue about thy
syntax of the annotation because this isn't final.

Greetings,
Christian

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to