File tree Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -14,17 +14,43 @@ Creating object literals in PHP is not as easy (or elegant) as in JavaScript or
1414
1515You can create object literals this way:
1616
17- ``` php
17+ ``` php
1818$object = new Object([
1919 "name" => "Fido",
2020 "barks" => true,
2121 "age" => 10
2222]);
2323```
2424
25+ or
26+
27+ ``` php
28+ $object = new Object([
29+ "name" => "Fido",
30+ "barks" => true,
31+ "age" => 10,
32+ 'say' => function ($self) {
33+ if ($self->barks) {
34+ return "Woof";
35+ }
36+ return "";
37+ }
38+ ]);
39+ ```
40+
41+ or
42+
43+ ``` php
44+ $object = new Object('{
45+ "name" : "Fido",
46+ "barks" : true,
47+ "age" : 10
48+ }');
49+ ```
50+
2551instead of:
2652
27- ``` php
53+ ``` php
2854$object = new Object();
2955$object->name = 'Fido';
3056$object->barks = true;
@@ -47,7 +73,7 @@ This class could be used while the RFC is not implemented.
4773
4874Via Composer
4975
50- ``` bash
76+ ``` bash
5177$ composer require josecelano/php-object-literal
5278```
5379
@@ -61,7 +87,7 @@ $ composer require josecelano/php-object-literal
6187
6288I try to follow TDD, as such I use [ phpunit] ( https://phpunit.de ) to test this library.
6389
64- ``` bash
90+ ``` bash
6591$ composer test
6692```
6793
You can’t perform that action at this time.
0 commit comments