2019-11-05 13:50:02 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
interface Ifoo {}
|
|
|
|
|
|
|
|
abstract class Foo implements Ifoo {
|
2019-11-05 16:56:18 -05:00
|
|
|
/**
|
|
|
|
* @param int $a
|
|
|
|
* @param float $b
|
|
|
|
* @param array $c
|
|
|
|
* @param callable $d
|
2020-12-04 11:18:21 -05:00
|
|
|
* @param string $e
|
2019-11-05 16:56:18 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
2020-12-04 11:18:21 -05:00
|
|
|
abstract public function bar(int $a, float $b, array $c, callable $d, string $e): string;
|
2019-11-05 13:50:02 -05:00
|
|
|
|
|
|
|
protected function doNothing(): void {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Docblock comment
|
|
|
|
*/
|
|
|
|
class FooBar extends Foo implements Ifoo {
|
2019-11-08 12:02:00 -05:00
|
|
|
public function bar(int $a, float $b, array $c, callable $d, string $e = 'default'): string
|
2019-11-05 13:50:02 -05:00
|
|
|
{
|
|
|
|
$cstr = print_r($c, TRUE);
|
|
|
|
$d();
|
|
|
|
|
|
|
|
return "{$a}, ${b}, " . $cstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function operations(int $a, int $b): int
|
|
|
|
{
|
2021-03-03 11:50:29 -05:00
|
|
|
$this?->x?->bar();
|
|
|
|
|
2019-11-05 13:50:02 -05:00
|
|
|
$this->doNothing();
|
|
|
|
|
|
|
|
$c = $a + $b;
|
|
|
|
$a = $c - $b;
|
|
|
|
|
|
|
|
$c = $a * $b;
|
|
|
|
$b = (int) ($c / $a);
|
|
|
|
|
|
|
|
return $c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 13:14:44 -05:00
|
|
|
trait Baz {
|
|
|
|
public function about(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'__CLASS__' => __CLASS__,
|
|
|
|
'__DIR__' => __DIR__,
|
|
|
|
'__FILE__' => __FILE__,
|
|
|
|
'__FUNCTION__' => __FUNCTION__,
|
|
|
|
'__LINE__' => __LINE__,
|
|
|
|
'__METHOD__' => __METHOD__,
|
|
|
|
'__NAMESPACE__' => __NAMESPACE__,
|
|
|
|
'__TRAIT__' => __TRAIT__,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 11:18:21 -05:00
|
|
|
$square = fn (int $x) => $x ** 2;
|
|
|
|
|
2021-03-03 13:14:44 -05:00
|
|
|
foreach ([-1, 0, 1, 2] as $x)
|
|
|
|
{
|
|
|
|
$not = match ($x) {
|
|
|
|
0 => 1,
|
|
|
|
1,-1 => 0,
|
|
|
|
default => 0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:50:02 -05:00
|
|
|
/*
|
|
|
|
* Multi-line comment
|
|
|
|
*/
|
|
|
|
$foobar = new FooBar();
|
|
|
|
|
2019-11-14 11:12:32 -05:00
|
|
|
$baz = ['a' => 'b'];
|
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
// C++ style comment
|
2019-11-05 13:50:02 -05:00
|
|
|
$x = 3;
|
|
|
|
|
2019-11-08 12:02:00 -05:00
|
|
|
# Perl-style comment
|
2019-11-06 13:57:19 -05:00
|
|
|
$y = [
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3
|
|
|
|
];
|
|
|
|
|
2019-11-14 11:12:32 -05:00
|
|
|
// Multi-line ternary statement
|
2021-03-03 20:23:12 -05:00
|
|
|
#{Attribute]
|
2019-11-14 11:12:32 -05:00
|
|
|
$q = ($x !== 2)
|
|
|
|
? 'yes'
|
|
|
|
: 'no';
|
|
|
|
|
2019-11-06 13:57:19 -05:00
|
|
|
/*
|
|
|
|
Heredoc
|
2019-11-08 12:02:00 -05:00
|
|
|
*/$z = $x + $y;
|
2019-11-05 13:50:02 -05:00
|
|
|
$sql = <<<SQL
|
|
|
|
SELECT * FROM "foo" WHERE "bar"='baz' AND id={$x};
|
|
|
|
SQL;
|
|
|
|
|
2019-11-05 16:56:18 -05:00
|
|
|
/* Nowdoc */
|
2019-11-05 13:50:02 -05:00
|
|
|
$template = <<<'TEMPLATE'
|
|
|
|
<foo>{x}</foo>
|
|
|
|
TEMPLATE;
|
|
|
|
|
|
|
|
?>
|
2020-12-04 11:18:21 -05:00
|
|
|
<!DOCTYPE html>
|
2019-11-05 13:50:02 -05:00
|
|
|
<html lang="en">
|
2020-12-04 11:18:21 -05:00
|
|
|
<head>
|
|
|
|
<title>HTML</title>
|
|
|
|
</head>
|
2019-11-05 13:50:02 -05:00
|
|
|
<body>
|
|
|
|
<h1><?= $_SERVER['HTTP_HOST'] ?></h1>
|
|
|
|
</body>
|
|
|
|
</html>
|
2019-11-15 16:19:34 -05:00
|
|
|
<?php exit(); ?>
|