Annotations support for PHP

https://github.com/eriknyk/addendum/blob/master/README.md

 

<?php

require_once 'annotations.php';

class Persistent{

    

}

/** @Persistent */

class Person {

   // some code

}

$reflection = new ReflectionAnnotatedClass('Person'); // by class name

echo $reflection->hasAnnotation('Persistent'); // true



$person = new Person();

$reflection = new ReflectionAnnotatedClass($person); // by instance



echo $reflection->hasAnnotation('Persistent'); // true

 





//demo2

 class Table extends Annotation {

     public $role;

    public $level;

 }



/** @Table(role="xxx",level=2) */

class Person2 {

   // some code

}

$reflection = new ReflectionAnnotatedClass('Person2'); // by class name    

println( $reflection->getAnnotation('Table')->value); // contains string "people"

var_dump($reflection->getAnnotation('Table'));



function println($str){

    echo $str."<br>";    

}

?>

你可能感兴趣的:(Annotations)