mirror of
https://github.com/igorsimdyanov/php8.git
synced 2025-08-10 03:01:01 +00:00
Глава 5: вычитка, нововведения PHP 8.0 и PHP 8.1
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
function handle_records(iterable $iterable)
|
||||
{
|
||||
echo count($iterable);
|
||||
}
|
||||
echo handle_records(1);
|
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
array_merge(['a'], ['b'], ['c'],);
|
@ -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'); //
|
@ -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);
|
@ -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
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
$str = <<< HTML_END
|
||||
Здесь располагается любой текст. До тех пор, пока не встретится
|
||||
метка, можно писать все что угодно
|
||||
HTML_END;
|
||||
echo $str;
|
5
variables/keywords.php
Normal file
5
variables/keywords.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$echo = 'echo';
|
||||
$foreach = 'foreach';
|
||||
echo $echo;
|
||||
echo $foreach;
|
6
variables/nowdoc.php
Normal file
6
variables/nowdoc.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$name = "Имя пользователя";
|
||||
$str = <<<'HTML_END'
|
||||
Переменные PHP не будут интерполироваться: $name
|
||||
HTML_END;
|
||||
echo $str;
|
2
variables/this.php
Normal file
2
variables/this.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$this = 'this.php'; // PHP Fatal error: Cannot re-assign $this
|
Reference in New Issue
Block a user