Skip to content

Commit be85d43

Browse files
Added more detailed upgrading docs (#340)
1 parent 22165d0 commit be85d43

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/.travis.yml export-ignore
88
/phpunit.xml.dist export-ignore
99
/README.md export-ignore
10+
/UPGRADING.md export-ignore

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ New in Version 3 is first-class support for multiline variables
1818
flexibility in terms of which parts of the environment we try to read and
1919
modify ([#300](https://github.com/vlucas/phpdotenv/pull/300)). Consequently,
2020
you will need to replace any occurrences of `new Dotenv(...)` with
21-
`Dotenv::create(...)`, since our new native constructor takes loader instance
22-
now, so that it can be truly customized if required. Finally, one should note
23-
the loader will no longer be trimming values
21+
`Dotenv::create(...)`, since our new native constructor takes a `Loader`
22+
instance now, so that it can be truly customized if required. Finally, one
23+
should note that the loader will no longer be trimming values
2424
([#302](https://github.com/vlucas/phpdotenv/pull/302)), moreover
2525
`Loader::load()` and its callers now return an associative array of the
2626
variables loaded with their values, rather than an array of raw lines from the
2727
environment file ([#306](https://github.com/vlucas/phpdotenv/pull/306)).
2828

2929
For more details, please see the
30-
[release notes](https://github.com/vlucas/phpdotenv/releases/tag/v3.0.0).
30+
[release notes](https://github.com/vlucas/phpdotenv/releases/tag/v3.0.0) and the [upgrading guide](UPGRADING.md).
3131

3232

3333
Why .env?

UPGRADING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Upgrading Guide
2+
3+
## V2 to V3
4+
5+
V3 has changed the way you initialize the `Dotenv` class. Consequently, you will need to replace any occurrences of new Dotenv(...) with Dotenv::create(...), since our new native constructor takes a `Loader` instance now.
6+
7+
`Loader::load()` and its callers now return an associative array of the variables loaded with their values.
8+
9+
Value parsing has been modified in the following ways:
10+
11+
1. For unquoted strings, as soon as there's a hash, it's treated as a comment start.
12+
2. We're being stricter about invalid escape sequences within quoted strings.
13+
3. We're no longer trimming the parsed values of quoted strings.
14+
4. Multiline quoted values are now permitted, and will be parsed by V3.
15+
16+
| input value | V2.5.2 | V2.6.1 | V3.3.1 |
17+
|-|-|-|-|
18+
| `foo#bar` | `foo#bar` | `foo#bar` | `foo` |
19+
| `foo # bar` | `foo` | `foo` | `foo` |
20+
| `"iiiiviiiixiiiiviiii\n"` | silent failure | `iiiviiiixiiiiviiii\n` | fails with invalid escape sequence exception |
21+
| `"iiiiviiiixiiiiviiii\\n"` | `iiiiviiiixiiiiviiii\n` | `iiiiviiiixiiiiviiii\n` | `iiiiviiiixiiiiviiii\n` |
22+
| `"foo\"bar"` | `foo"bar` | `foo"bar` | `foo"bar` |
23+
| `" foo "` | `foo` with whitespace trimmed | `foo` with whitespace trimmed | `foo` with 2 spaces in front and one after |
24+
25+
In double quoted strings, double quotes and backslashes need escaping with a backslash, and in single quoted strings, single quote and backslashes need escaping with a backslash. In v2.5.2, forgetting an escape can lead to odd results due to the regex running out of stack, but this was fixed in 2.6 and 3.3, with 2.6 allowing you to continue after an unescaped backslash, but 3.3 not.
26+
27+
Finally, it's possible to use phpdotenv V3 in a threaded environment, instructing it to not call any functions that are not tread-safe:
28+
29+
```php
30+
<?php
31+
32+
use Dotenv\Environment\Adapter\EnvConstAdapter;
33+
use Dotenv\Environment\Adapter\ServerConstAdapter;
34+
use Dotenv\Environment\DotenvFactory;
35+
use Dotenv\Dotenv;
36+
37+
$factory = new DotenvFactory([new EnvConstAdapter(), new ServerConstAdapter()]);
38+
39+
Dotenv::create($path, null, $factory)->load();
40+
```

0 commit comments

Comments
 (0)