Skip to content

Commit f502d23

Browse files
author
Celano, Jose
committed
update README
1 parent f759962 commit f502d23

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,43 @@ Creating object literals in PHP is not as easy (or elegant) as in JavaScript or
1414

1515
You 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+
2551
instead 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

4874
Via 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

6288
I 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

0 commit comments

Comments
 (0)