- var_dump: documentation ( source)
<?php
#[Attribute]
enum DemoEnum {}
#[Attribute]
trait DemoTrait {}
#[Attribute]
abstract class DemoAbstract {}
#[Attribute]
interface DemoInterface {}
#[DemoEnum]
#[DemoTrait]
#[DemoAbstract]
#[DemoInterface]
function usesWrongAttrib() {}
$r = new ReflectionFunction( 'usesWrongAttrib' );
$a = $r->getAttributes();
var_dump( $a );
foreach ( $a as $attrib ) {
try {
$attrib->newInstance();
} catch ( Error $e ) {
echo get_class( $e ) . ": " . $e->getMessage() . "\n";
}
}