Глава 5: вычитка, нововведения PHP 8.0 и PHP 8.1

This commit is contained in:
Igor Simdyanov
2022-04-12 23:05:00 +03:00
parent 79646406c3
commit 046834d79f
10 changed files with 16 additions and 52 deletions

View File

@ -1,6 +0,0 @@
<?php
function handle_records(iterable $iterable)
{
echo count($iterable);
}
echo handle_records(1);

View File

@ -1,2 +0,0 @@
<?php
array_merge(['a'], ['b'], ['c'],);

View File

@ -1,17 +0,0 @@
<?php
enum Suit {
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
$val = Suit::Diamonds;
function pick_a_card(Suit $suit) {
echo $suit->name.'<br />';
}
pick_a_card($val); // OK
pick_a_card(Suit::Clubs); // OK
pick_a_card('Spades'); //

View File

@ -1,18 +0,0 @@
<?php
class Test {
public function __construct(
public readonly int $i = 0,
public readonly array $ary = [],
) {}
}
$test = new Test;
$test->i += 1;
$test->i++;
++$test->i;
$test->ary[] = 1;
$test->ary[0][] = 1;
$ref =& $test->i;
$test->i =& $ref;
byRef($test->i);
foreach ($test as &$prop);

View File

@ -1,4 +1,4 @@
<?php
$str = '12.6';
$number = 3 + $str;
echo $number; // 15.6
echo '12wet56.7' + 10; // 12 + 10 = 22
echo '<br />';
echo 14 + 'четырнадцать'; // 14 + 0 = 14

View File

@ -1,6 +0,0 @@
<?php
$str = <<< HTML_END
Здесь располагается любой текст. До тех пор, пока не встретится
метка, можно писать все что угодно
HTML_END;
echo $str;

5
variables/keywords.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$echo = 'echo';
$foreach = 'foreach';
echo $echo;
echo $foreach;

6
variables/nowdoc.php Normal file
View File

@ -0,0 +1,6 @@
<?php
$name = "Имя пользователя";
$str = <<<'HTML_END'
Переменные PHP не будут интерполироваться: $name
HTML_END;
echo $str;

2
variables/this.php Normal file
View File

@ -0,0 +1,2 @@
<?php
$this = 'this.php'; // PHP Fatal error: Cannot re-assign $this