You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51-13Lines changed: 51 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ This document is a cheatsheet for PHP you will frequently encounter in modern pr
15
15
16
16
This guide is not intended to teach you PHP from the ground up, but to help developers with basic knowledge who may struggle to get familiar with modern codebases (or let's say to learn Laravel or Symfony for instance) because of the new PHP concepts and features introduced over the years.
17
17
18
-
> **Note:** Concepts introduced here are based on the most recent version of PHP available ([PHP 8.1](https://www.php.net/releases/8.1/en.php) at the time of the last update)
18
+
> **Note:** Concepts introduced here are based on the most recent version of PHP available ([PHP 8.3](https://www.php.net/releases/8.3/en.php) at the time of the last update)
19
19
20
20
### Complementary Resources
21
21
@@ -29,16 +29,17 @@ When you struggle to understand a notion, I suggest you look for answers on the
$b = myFunction('foo'); // TypeError: myFunction(): Argument #1 ($param) must be of type Status, string given
1609
1611
```
1610
1612
1611
-
### Enum methods
1613
+
####Enum methods
1612
1614
1613
1615
You can define methods with an Enum :
1614
1616
@@ -1636,7 +1638,7 @@ $a = Status::DRAFT;
1636
1638
$a->label(); // 'Not ready...'
1637
1639
```
1638
1640
1639
-
### Backed values
1641
+
####Backed values
1640
1642
1641
1643
Sometimes you need to assign a proper value to each enum case (ex: to store it in a database, comparison, etc). You should define the type of the back value. Here is an example with a backed value defined as an `int` :
1642
1644
@@ -1664,3 +1666,39 @@ enum Status: string
1664
1666
-[Enums manual on PHP official documentation](https://www.php.net/manual/en/language.enumerations.php)
1665
1667
-[Enums on PHP.Watch](https://php.watch/versions/8.0/match-expression)
1666
1668
-[Enums style guide on stitcher's blog](https://stitcher.io/blog/php-enum-style-guide)
When you want to define a string value that contains multiple lines, you generally use double quotes and escape line breaks:
1675
+
1676
+
```php
1677
+
$string = "Hello\nWorld";
1678
+
```
1679
+
1680
+
Since PHP 7.3, there is a new option for specifying a string value over multiple lines. By placing it between an opening identifier and a closing identifier:
1681
+
1682
+
```php
1683
+
$string = <<<IDENTIFIER
1684
+
Hello
1685
+
World
1686
+
IDENTIFIER;
1687
+
```
1688
+
1689
+
Youcanuseanyidentifieryouwant,butitmustbethesameatthebeginningandattheendofthestring.Itcan't be a variable.
1690
+
1691
+
The closing identifier can be followed by other code on the same line:
1692
+
1693
+
```php
1694
+
$array = ['foo', 'bar', <<<IDENTIFIER
1695
+
hello
1696
+
world
1697
+
IDENTIFIER, 'baz', 'qux',
1698
+
];
1699
+
```
1700
+
1701
+
#### External resource
1702
+
1703
+
- [Relaxed heredoc and nowdoc on PHP.Watch](https://php.watch/versions/7.3/relaxed-heredoc-nowdoc)
1704
+
- [Heredoc nowdoc on andycarter.dev'sblog](https://andycarter.dev/blog/what-are-php-heredoc-nowdoc)
0 commit comments