Skip to content

Commit 7faeee0

Browse files
committed
add heredoc / nowdoc section
1 parent 9d79b45 commit 7faeee0

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

README.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This document is a cheatsheet for PHP you will frequently encounter in modern pr
1515

1616
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.
1717

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)
1919
2020
### Complementary Resources
2121

@@ -29,16 +29,17 @@ When you struggle to understand a notion, I suggest you look for answers on the
2929

3030
### Recent PHP releases
3131

32-
| Version |Release date|
33-
|----------------------------------------------|---|
34-
| [PHP 8.2](https://www.php.net/releases/8.2/en.php) |December 2022|
35-
| [PHP 8.1](https://www.php.net/releases/8.1/en.php) |November 2021|
36-
| [PHP 8.0](https://www.php.net/releases/8.0/en.php) |November 2020|
37-
| PHP 7.4 |November 2019|
38-
| PHP 7.3 |December 2018|
39-
| PHP 7.2 |November 2017|
40-
| PHP 7.1 |December 2016|
41-
| PHP 7.0 |December 2015|
32+
| Version | Release date |
33+
|----------------------------------------------------|---------------|
34+
| [PHP 8.3](https://www.php.net/releases/8.3/en.php) | December 2023 |
35+
| [PHP 8.2](https://www.php.net/releases/8.2/en.php) | December 2022 |
36+
| [PHP 8.1](https://www.php.net/releases/8.1/en.php) | November 2021 |
37+
| [PHP 8.0](https://www.php.net/releases/8.0/en.php) | November 2020 |
38+
| PHP 7.4 | November 2019 |
39+
| PHP 7.3 | December 2018 |
40+
| PHP 7.2 | November 2017 |
41+
| PHP 7.1 | December 2016 |
42+
| PHP 7.0 | December 2015 |
4243

4344
More infos on [php.net](https://www.php.net/supported-versions.php).
4445

@@ -63,6 +64,7 @@ More infos on [php.net](https://www.php.net/supported-versions.php).
6364
+ [Match expression](#match-expression)
6465
+ [Stringable interface](#stringable-interface)
6566
+ [Enums](#enums)
67+
+ [Multiple lines string syntax](#multiple-lines-string-syntax)
6668

6769
## Notions
6870

@@ -1608,7 +1610,7 @@ $a = myFunction(Status::DRAFT);
16081610
$b = myFunction('foo'); // TypeError: myFunction(): Argument #1 ($param) must be of type Status, string given
16091611
```
16101612

1611-
### Enum methods
1613+
#### Enum methods
16121614

16131615
You can define methods with an Enum :
16141616

@@ -1636,7 +1638,7 @@ $a = Status::DRAFT;
16361638
$a->label(); // 'Not ready...'
16371639
```
16381640

1639-
### Backed values
1641+
#### Backed values
16401642

16411643
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` :
16421644

@@ -1664,3 +1666,39 @@ enum Status: string
16641666
- [Enums manual on PHP official documentation](https://www.php.net/manual/en/language.enumerations.php)
16651667
- [Enums on PHP.Watch](https://php.watch/versions/8.0/match-expression)
16661668
- [Enums style guide on stitcher's blog](https://stitcher.io/blog/php-enum-style-guide)
1669+
1670+
### Multiple lines string syntax
1671+
1672+
![php-version-73](https://shields.io/badge/php->=7.3-blue)
1673+
1674+
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+
You can use any identifier you want, but it must be the same at the beginning and at the end of the string. It can'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's blog](https://andycarter.dev/blog/what-are-php-heredoc-nowdoc)

0 commit comments

Comments
 (0)