php-kilo/test.php
Timothy Warren c8be79d2d8
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit
Add more attributes to test file
2022-09-01 09:29:07 -04:00

136 lines
2.1 KiB
PHP

<?php declare(strict_types=1);
interface Ifoo {}
// Let's see emoji! 🕯️😸⛩⛪
abstract class Foo implements Ifoo {
/**
* @param int $a
* @param float $b
* @param array $c
* @param callable $d
* @param string $e
* @return string
*/
abstract public function bar(int $a, float $b, array $c, callable $d, string $e): string;
#[ReturnTypeWillChange]
protected function doNothing(): void {}
}
#[Attribute]
#[AllowDynamicProperties]
class Test {
public function __construct(public string $foo, public string $bar) {}
}
/**
* Docblock comment
*/
class FooBar extends Foo implements Ifoo {
public function bar(int $a, float $b, array $c, callable $d, #[SensitiveParameter] string $e = 'default'): string
{
$cstr = print_r($c, TRUE);
$d();
$r = $this->operations($a, (int)$b);
return "{$a}, ${b}, " . $cstr . " = {$r}";
}
#[Test('a', 'b')]
private function operations(int $a, int $b): int
{
$this?->x?->bar();
$this->doNothing();
$c = $a + $b;
$a = $c - $b;
$c = $a * $b;
$b = (int) ($c / $a);
return $c;
}
}
trait Baz {
public function about(): array
{
return [
'__CLASS__' => __CLASS__,
'__DIR__' => __DIR__,
'__FILE__' => __FILE__,
'__FUNCTION__' => __FUNCTION__,
'__LINE__' => __LINE__,
'__METHOD__' => __METHOD__,
'__NAMESPACE__' => __NAMESPACE__,
'__TRAIT__' => __TRAIT__,
];
}
}
class BazFoo {
use Baz;
}
$square = fn (int $x) => $x ** 2;
foreach ([-1, 0, 1, 2] as $x)
{
$not = match ($x) {
0 => 1,
1,-1 => 0,
default => 0,
};
}
/*
* Multi-line comment
*/
$foobar = new FooBar();
$baz = ['a' => 'b'];
// C++ style comment
$x = 3;
# Perl-style comment
$y = [
1,
2,
3
];
// Multi-line ternary statement
#{Attribute]
$q = ($x !== 2)
? 'yes'
: 'no';
/*
Heredoc
*/$z = $x + $y[0];
$sql = <<<SQL
SELECT * FROM "foo" WHERE "bar"='baz' AND id={$x};
SQL;
/* Nowdoc */
$template = <<<'TEMPLATE'
<foo>{x}</foo>
TEMPLATE;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML</title>
</head>
<body>
<h1>Test</h1>
<div><?php $bf = new BazFoo(); print_r($bf->about()) ?></div>
</body>
</html>
<?php exit(); ?>