PHP code example of php-static-analysis / attributes
1. Go to this page and download the library: Download php-static-analysis/attributes 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/ */
php-static-analysis / attributes example snippets
class ArrayAdder
{
/** @var array<string> */
private array $result;
/**
* @param array<string> $array1 the first array
* @param array<string> $array2 the second array
* @return array<string>
*/
public function addArrays(array $array1, array $array2): array
{
$this->result = $array1 + $array2;
return $this->result;
}
}
use PhpStaticAnalysis\Attributes\Type;
use PhpStaticAnalysis\Attributes\Param;
use PhpStaticAnalysis\Attributes\Returns;
class ArrayAdder
{
#[Type('array<string>')]
private array $result;
#[Param(array1: 'array<string>')] // the first array
#[Param(array2: 'array<string>')] // the second array
#[Returns('array<string>')]
public function addArrays(array $array1, array $array2): array
{
$this->array = $array1 + $array2;
return $this->array;
}
}