Skip to content

Commit 71bd850

Browse files
committed
added coding standard section about global functions and constants
1 parent bd75250 commit 71bd850

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

contributing/cs/coding-standard.texy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ public function find(string $dir, array $options): array
109109
```
110110

111111

112+
Globální funkce a konstanty
113+
===========================
114+
115+
Globální funkce a konstanty se píší bez úvodního zpětného lomítka, tedy `count($arr)` nikoliv `\count($arr)`. Pro funkce, které umí PHP optimalizovat, uvedeme na začátku souboru `use function`, aby je kompilátor mohl přeložit efektivněji. Jedná se zejména o funkce jako `count`, `strlen`, `is_array`, `is_string`, `is_scalar`, `sprintf` aj. Funkce se uvádějí na jednom řádku, aby úvodní blok importů nebyl zbytečně velký:
116+
117+
```php
118+
use Nette;
119+
use function count, is_array, is_scalar, sprintf;
120+
```
121+
122+
Výjimečně takto uvádíme i konstanty, u kterých může znalost hodnoty posloužit kompilátoru:
123+
124+
```php
125+
use const PHP_OS_FAMILY;
126+
```
127+
128+
112129
Tabulátory místo mezer
113130
======================
114131

contributing/en/coding-standard.texy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ public function find(string $dir, array $options): array
109109
```
110110

111111

112+
Global Functions and Constants
113+
==============================
114+
115+
Global functions and constants are written without a leading backslash, i.e., `count($arr)` not `\count($arr)`. For functions that PHP can optimize, add `use function` at the beginning of the file so the compiler can translate them more efficiently. These include functions like `count`, `strlen`, `is_array`, `is_string`, `is_scalar`, `sprintf`, etc. Functions are listed on a single line to keep the import block compact:
116+
117+
```php
118+
use Nette;
119+
use function count, is_array, is_scalar, sprintf;
120+
```
121+
122+
Occasionally, we also import constants whose value knowledge may help the compiler:
123+
124+
```php
125+
use const PHP_OS_FAMILY;
126+
```
127+
128+
112129
Tabs Instead of Spaces
113130
======================
114131

0 commit comments

Comments
 (0)