php-kilo/test.php
Timothy J Warren 6df5bda8f2
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit
Attempt to fix CI tests
2021-03-03 20:23:12 -05:00

119 lines
1.7 KiB
PHP

<?php declare(strict_types=1);
interface Ifoo {}
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;
protected function doNothing(): void {}
}
/**
* Docblock comment
*/
class FooBar extends Foo implements Ifoo {
public function bar(int $a, float $b, array $c, callable $d, string $e = 'default'): string
{
$cstr = print_r($c, TRUE);
$d();
return "{$a}, ${b}, " . $cstr;
}
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__,
];
}
}
$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;
$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><?= $_SERVER['HTTP_HOST'] ?></h1>
</body>
</html>
<?php exit(); ?>