-
Notifications
You must be signed in to change notification settings - Fork 1
/
00-quick-migration.php
49 lines (39 loc) · 1.03 KB
/
00-quick-migration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
// Code before migrating from built-in functions to suin/json's functions.
namespace BeforeMigration {
$json = json_encode([1, 2, 3]); // this is built-in function
var_dump($json);
$value = json_decode($json); // this is built-in function
var_dump($value);
// Output:
// string(7) "[1,2,3]"
// array(3) {
// [0]=>
// int(1)
// [1]=>
// int(2)
// [2]=>
// int(3)
// }
}
// Code after migrating from built-in functions to suin/json's functions.
namespace AfterMigration {
// Add these two lines to migrate:
use function Suin\Json\json_decode;
use function Suin\Json\json_encode;
$json = json_encode([1, 2, 3]); // Now this is this library's function.
var_dump($json);
$value = json_decode($json); // Now this is this library's function.
var_dump($value);
// Output:
// string(7) "[1,2,3]"
// array(3) {
// [0]=>
// int(1)
// [1]=>
// int(2)
// [2]=>
// int(3)
// }
}