PHP code example of reedware / is-attribute

1. Go to this page and download the library: Download reedware/is-attribute library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reedware / is-attribute example snippets


#[Attribute]
class SetUp
{
    //
}

function is_attribute(string|object|null $class, ?int $target = null, int $match = TARGET_MATCH_EQUALS): bool

echo is_attribute(SetUp::class); // true
echo is_attribute(CopyFile::class); // false

#[Attribute(Attribute::TARGET_CLASS_CONSTANT|Attribute::TARGET_PROPERTY)]
class Serialize
{
    //
}

echo is_attribute(Serialize::class, Attribute::TARGET_CLASS_CONSTANT|Attribute::TARGET_PROPERTY); // true

echo is_attribute(Serialize::class, Attribute::TARGET_CLASS_CONSTANT); // false
echo is_attribute(Serialize::class, Attribute::TARGET_PROPERTY); // false

echo is_attribute(Serialize::class, Attribute::TARGET_ALL); // false

echo is_attribute(Serialize::class, Attribute::TARGET_CLASS_CONSTANT, TARGET_MATCH_INCLUDES); // true
echo is_attribute(Serialize::class, Attribute::TARGET_PROPERTY, TARGET_MATCH_INCLUDES); // true
echo is_attribute(Serialize::class, Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER, TARGET_MATCH_INCLUDES); // false

echo is_attribute(Serialize::class, Attribute::TARGET_CLASS_CONSTANT, TARGET_MATCH_INCLUDES); // true
echo is_attribute(Serialize::class, Attribute::TARGET_PROPERTY, TARGET_MATCH_INCLUDES); // true
echo is_attribute(Serialize::class, Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER, TARGET_MATCH_INCLUDES); // true