You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/nette/php-generator/releases)[](https://packagist.org/packages/nette/php-generator)
4
+
5
+
<!---->
3
6
4
7
Are you looking for a tool to generate PHP code for [classes](#classes), [functions](#global-functions), or complete [PHP files](#php-files)?
5
8
9
+
<h3>
10
+
6
11
✅ Supports all the latest PHP features like [enums](#enums), [attributes](#attributes), etc.<br>
7
12
✅ Allows you to easily modify [existing classes](#generating-from-existing-ones)<br>
8
13
✅ Output compliant with [PSR-12 / PER coding style](#printer-and-psr-compliance)<br>
9
14
✅ Highly mature, stable, and widely used library
10
15
16
+
</h3>
17
+
18
+
<!---->
11
19
12
20
Installation
13
21
------------
@@ -18,8 +26,9 @@ Download and install the library using the [Composer](https://doc.nette.org/en/b
18
26
composer require nette/php-generator
19
27
```
20
28
21
-
For PHP compatibility, see the [table](#compatibility-table). Documentation even for older versions can be found on the [library's website](https://doc.nette.org/php-generator).
29
+
PhpGenerator 4.1 is compatible with PHP 8.0 to 8.3. Documentation can be found on the [library's website](https://doc.nette.org/php-generator).
22
30
31
+
<!---->
23
32
24
33
[Support Me](https://github.com/sponsors/dg)
25
34
--------------------------------------------
@@ -30,6 +39,7 @@ Do you like PHP Generator? Are you looking forward to the new features?
For each *case*, you can add a comment or [attributes](#attributes) using `addComment()` or `addAttribute()`.
249
261
262
+
<!---->
250
263
251
264
Anonymous Classes
252
265
-----------------
@@ -272,6 +285,7 @@ $obj = new class ($val) {
272
285
};
273
286
```
274
287
288
+
<!---->
275
289
276
290
Global Functions
277
291
----------------
@@ -298,6 +312,7 @@ function foo($a, $b)
298
312
}
299
313
```
300
314
315
+
<!---->
301
316
302
317
Anonymous Functions
303
318
-------------------
@@ -325,6 +340,7 @@ function ($a, $b) use (&$c) {
325
340
}
326
341
```
327
342
343
+
<!---->
328
344
329
345
Short Arrow Functions
330
346
---------------------
@@ -346,6 +362,7 @@ The result is:
346
362
fn($a, $b) => $a + $b
347
363
```
348
364
365
+
<!---->
349
366
350
367
Method and Function Signatures
351
368
------------------------------
@@ -386,6 +403,7 @@ function count(...$items)
386
403
}
387
404
```
388
405
406
+
<!---->
389
407
390
408
Method and Function Bodies
391
409
--------------------------
@@ -476,6 +494,7 @@ function foo($a)
476
494
}
477
495
```
478
496
497
+
<!---->
479
498
480
499
Printer and PSR Compliance
481
500
--------------------------
@@ -531,6 +550,7 @@ The standard `Printer` formats the code as we do throughout Nette. Since Nette w
531
550
The major difference is the use of tabs instead of spaces. We know that by using tabs in our projects, we allow for width customization, which is [essential for people with visual impairments](https://doc.nette.org/en/contributing/coding-standard#toc-tabs-instead-of-spaces).
532
551
An example of a minor difference is placing the curly brace on a separate line for functions and methods, always. The PSR recommendation seems illogical to us and [leads to reduced code clarity](https://doc.nette.org/en/contributing/coding-standard#toc-wrapping-and-braces).
533
552
553
+
<!---->
534
554
535
555
Types
536
556
-----
@@ -549,6 +569,7 @@ $member->setType(null); // removes the type
0 commit comments