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)
3
4
4
5
Are you looking for a tool to generate PHP code for [classes](#classes), [functions](#global-functions), or complete [PHP files](#php-files)?
5
6
7
+
<h3>
8
+
6
9
✅ Supports all the latest PHP features like [enums](#enums), [attributes](#attributes), etc.<br>
7
10
✅ Allows you to easily modify [existing classes](#generating-from-existing-ones)<br>
8
11
✅ Output compliant with [PSR-12 / PER coding style](#printer-and-psr-compliance)<br>
9
12
✅ Highly mature, stable, and widely used library
10
13
14
+
</h3>
15
+
16
+
<!---->
11
17
12
18
Installation
13
19
------------
@@ -18,8 +24,9 @@ Download and install the library using the [Composer](https://doc.nette.org/en/b
18
24
composer require nette/php-generator
19
25
```
20
26
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).
27
+
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
28
29
+
<!---->
23
30
24
31
[Support Me](https://github.com/sponsors/dg)
25
32
--------------------------------------------
@@ -30,6 +37,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
259
260
+
<!---->
250
261
251
262
Anonymous Classes
252
263
-----------------
@@ -272,6 +283,7 @@ $obj = new class ($val) {
272
283
};
273
284
```
274
285
286
+
<!---->
275
287
276
288
Global Functions
277
289
----------------
@@ -298,6 +310,7 @@ function foo($a, $b)
298
310
}
299
311
```
300
312
313
+
<!---->
301
314
302
315
Anonymous Functions
303
316
-------------------
@@ -325,6 +338,7 @@ function ($a, $b) use (&$c) {
325
338
}
326
339
```
327
340
341
+
<!---->
328
342
329
343
Short Arrow Functions
330
344
---------------------
@@ -346,6 +360,7 @@ The result is:
346
360
fn($a, $b) => $a + $b
347
361
```
348
362
363
+
<!---->
349
364
350
365
Method and Function Signatures
351
366
------------------------------
@@ -386,6 +401,7 @@ function count(...$items)
386
401
}
387
402
```
388
403
404
+
<!---->
389
405
390
406
Method and Function Bodies
391
407
--------------------------
@@ -476,6 +492,7 @@ function foo($a)
476
492
}
477
493
```
478
494
495
+
<!---->
479
496
480
497
Printer and PSR Compliance
481
498
--------------------------
@@ -531,6 +548,7 @@ The standard `Printer` formats the code as we do throughout Nette. Since Nette w
531
548
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
549
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
550
551
+
<!---->
534
552
535
553
Types
536
554
-----
@@ -549,6 +567,7 @@ $member->setType(null); // removes the type
0 commit comments