Обновить ридми

This commit is contained in:
mzhoot 2026-05-31 18:52:40 +03:00
parent 25854d0b99
commit b21c04412d

555
README.md
View file

@ -1,3 +1,4 @@
```markdown
<div align="center"> <div align="center">
<a href="https://www.php.net"> <a href="https://www.php.net">
<img <img
@ -7,168 +8,408 @@
</a> </a>
</div> </div>
# The PHP Interpreter # The PHP Interpreter (Русский форк — PHP-RU)
PHP is a popular general-purpose scripting language that is especially suited to PHP is a popular general-purpose scripting language that is especially suited to
web development. Fast, flexible and pragmatic, PHP powers everything from your web development. Fast, flexible and pragmatic, PHP powers everything from your
blog to the most popular websites in the world. blog to the most popular websites in the world.
**Этот форк добавляет поддержку русских ключевых слов и логических констант, сохраняя полную совместимость с оригинальным синтаксисом.**
---
## 📋 Русские ключевые слова
| Оригинал | Русский |
|----------|---------|
| `if` | `если` |
| `else` | `иначе` |
| `elseif` | `и_если` |
| `endif` | `к_если` |
| `while` | `пока` |
| `endwhile` | `к_пока` |
| `do` | `делать` |
| `for` | `для` |
| `endfor` | `к_для` |
| `foreach` | `д_кажд` |
| `endforeach` | `к_д_кажд` |
| `break` | `брейк` |
| `continue` | `далее` |
| `function` | `функц` |
| `return` | `возврат` |
| `echo` | `эхо` |
| `print` | `печать` |
| `class` | `класс` |
| `interface` | `интерфейс` |
| `trait` | `примесь` |
| `extends` | `расшир` |
| `implements` | `реализ` |
| `abstract` | `абстракт` |
| `final` | `окончат` |
| `static` | `статич` |
| `public` | `публ` |
| `protected` | `защищ` |
| `private` | `приватн` |
| `readonly` | `т_чтение` |
| `namespace` | `п_имён` |
| `use` | `использ` |
| `insteadof` | `вместоД` |
| `global` | `глобал` |
| `var` | `перем` |
| `isset` | `устан` |
| `unset` | `удалить` |
| `empty` | `пуст` |
| `list` | `список` |
| `array` | `массив` |
| `callable` | `вызываемый` |
| `clone` | `клон` |
| `new` | `нов` |
| `attribute` | `атрибут` |
| `exit` | `выход` |
| `die` | `стоп` |
| `goto` | `переход` |
| `switch` | `перекл` |
| `endswitch` | `к_перекл` |
| `case` | `случай` |
| `default` | `по_умолч` |
| `match` | `сопостав` |
| `try` | `проб` |
| `catch` | `отлов` |
| `finally` | `к_проб` |
| `throw` | `бросить` |
| `yield` | `отдать` |
| `yield from` | `отдать из` |
| `true` | `правда` |
| `false` | `ложь` |
| `null` | `пусто` |
---
## 🧪 Однострочные тесты (оригинал + русский)
### Условные операторы
```bash
# if / если
./sapi/cli/php -r 'if (5 > 3) { echo "OK\n"; }'
./sapi/cli/php -r 'если (5 > 3) { эхо "OK\n"; }'
# else / иначе
./sapi/cli/php -r 'if (0) { echo "A"; } else { echo "B\n"; }'
./sapi/cli/php -r 'если (0) { эхо "A"; } иначе { эхо "B\n"; }'
# elseif / и_если
./sapi/cli/php -r '$x=2; if($x==1){echo"A";}elseif($x==2){echo"B\n";}'
./sapi/cli/php -r '$x=2; если($x==1){эхо"A";}и_если($x==2){эхо"B\n";}'
# endif / к_если
./sapi/cli/php -r 'if (1): echo "OK\n"; endif;'
./sapi/cli/php -r 'если (1): эхо "OK\n"; к_если;'
```
### Циклы
```bash
# while / пока
./sapi/cli/php -r '$i=0; while($i<3){echo $i." "; $i++;}'
./sapi/cli/php -r '$i=0; пока($i<3){эхо $i." "; $i++;}'
# endwhile / к_пока
./sapi/cli/php -r '$i=0; while($i<3): echo $i." "; $i++; endwhile;'
./sapi/cli/php -r '$i=0; пока($i<3): эхо $i." "; $i++; к_пока;'
# do / делать
./sapi/cli/php -r '$i=0; do { echo $i." "; $i++; } while($i<3);'
./sapi/cli/php -r '$i=0; делать { эхо $i." "; $i++; } пока($i<3);'
# for / для
./sapi/cli/php -r 'for($i=0;$i<3;$i++){ echo $i." "; }'
./sapi/cli/php -r 'для($i=0;$i<3;$i++){ эхо $i." "; }'
# endfor / к_для
./sapi/cli/php -r 'for($i=0;$i<3;$i++): echo $i." "; endfor;'
./sapi/cli/php -r 'для($i=0;$i<3;$i++): эхо $i." "; к_для;'
# break / брейк
./sapi/cli/php -r 'for($i=0;$i<5;$i++){ if($i==3)break; echo $i." "; }'
./sapi/cli/php -r 'для($i=0;$i<5;$i++){ если($i==3)брейк; эхо $i." "; }'
# continue / далее
./sapi/cli/php -r 'for($i=0;$i<5;$i++){ if($i==2)continue; echo $i." "; }'
./sapi/cli/php -r 'для($i=0;$i<5;$i++){ если($i==2)далее; эхо $i." "; }'
```
### Foreach
```bash
# foreach / д_кажд
./sapi/cli/php -r '$a=[1,2,3]; foreach($a as $v){ echo $v." "; }'
./sapi/cli/php -r '$a=[1,2,3]; д_кажд($a как $v){ эхо $v." "; }'
# endforeach / к_д_кажд
./sapi/cli/php -r '$a=[1,2,3]; foreach($a as $v): echo $v." "; endforeach;'
./sapi/cli/php -r '$a=[1,2,3]; д_кажд($a как $v): эхо $v." "; к_д_кажд;'
```
### Функции
```bash
# Простая функция
./sapi/cli/php -r 'function square($x){return $x*$x;} echo square(5);'
./sapi/cli/php -r 'функц квадрат($x){возврат $x*$x;} эхо квадрат(5);'
# Функция с двумя параметрами
./sapi/cli/php -r 'function sum($a,$b){return $a+$b;} echo sum(10,20);'
./sapi/cli/php -r 'функц сумма($a,$b){возврат $a+$b;} эхо сумма(10,20);'
# Рекурсивная функция
./sapi/cli/php -r 'function fact($n){return $n<=1?1:$n*fact($n-1);} echo fact(5);'
./sapi/cli/php -r 'функц факт($n){возврат $n<=1?1:$n*факт($n-1);} эхо факт(5);'
# Анонимная функция (замыкание)
./sapi/cli/php -r '$f=fn($x)=>$x*2; echo $f(5);'
./sapi/cli/php -r '$f=фн($x)=>$x*2; эхо $f(5);'
# Функция с русскими именами параметров
./sapi/cli/php -r 'function power($base,$exp){return pow($base,$exp);} echo power(2,3);'
./sapi/cli/php -r 'функц степень($основание,$показатель){возврат pow($основание,$показатель);} эхо степень(2,3);'
# Функция с типом возврата
./sapi/cli/php -r 'function add(int $a,int $b):int{return $a+$b;} echo add(5,3);'
./sapi/cli/php -r 'функц сложить(int $a,int $b):int{возврат $a+$b;} эхо сложить(5,3);'
# Функция с значением по умолчанию
./sapi/cli/php -r 'function greet($name="World"){return "Hello $name";} echo greet();'
./sapi/cli/php -r 'функц привет($имя="Мир"){возврат "Привет $имя";} эхо привет();'
# Функция с передачей по ссылке
./sapi/cli/php -r 'function add5(&$x){$x+=5;} $a=10; add5($a); echo $a;'
./sapi/cli/php -r 'функц добавить5(&$x){$x+=5;} $a=10; добавить5($a); эхо $a;'
# Функция с переменным числом аргументов
./sapi/cli/php -r 'function sumAll(...$nums){return array_sum($nums);} echo sumAll(1,2,3,4);'
./sapi/cli/php -r 'функц суммаВсех(...$числа){возврат array_sum($числа);} эхо суммаВсех(1,2,3,4);'
# Функция с массивом
./sapi/cli/php -r 'function range2($n){return range(1,$n);} print_r(range2(3));'
./sapi/cli/php -r 'функц диапазон($n){возврат range(1,$n);} print_r(диапазон(3));'
# Функция max
./sapi/cli/php -r 'function max2($a,$b){return $a>$b?$a:$b;} echo max2(7,3);'
./sapi/cli/php -r 'функц максимум($a,$b){возврат $a>$b?$a:$b;} эхо максимум(7,3);'
# Вложенные функции (замыкание)
./sapi/cli/php -r 'function multiplier($f){return fn($x)=>$x*$f;} $double=multiplier(2); echo $double(5);'
./sapi/cli/php -r 'функц множитель($f){return фн($x)=>$x*$f;} $двойной=множитель(2); эхо $двойной(5);'
# Функция с проверкой четности
./sapi/cli/php -r 'function isEven($n){return $n%2==0;} echo isEven(4)?"Even":"Odd";'
./sapi/cli/php -r 'функц четное($n){возврат $n%2==0;} эхо четное(4)?"Чет":"Нечет";'
# Функция с глобальной переменной
./sapi/cli/php -r '$factor=3; function scale($x){global $factor; return $x*$factor;} echo scale(5);'
./sapi/cli/php -r '$коэф=3; функц масштаб($x){глобал $коэф; возврат $x*$коэф;} эхо масштаб(5);'
# Функция со статической переменной
./sapi/cli/php -r 'function counter(){static $c=0; return ++$c;} echo counter()." ".counter()." ".counter();'
./sapi/cli/php -r 'функц счетчик(){статич $c=0; возврат ++$c;} эхо счетчик()." ".счетчик()." ".счетчик();'
# Функция с деструктуризацией массива
./sapi/cli/php -r 'function swap($a,$b){return[$b,$a];} list($x,$y)=swap(1,2); echo "$x $y";'
./sapi/cli/php -r 'функц обмен($a,$b){возврат[$b,$a];} список($x,$y)=обмен(1,2); эхо "$x $y";'
# Комбинированный тест
./sapi/cli/php -r 'function add($a,$b){return $a+$b;} function mul($a,$b){return $a*$b;} echo add(3,mul(2,4));'
./sapi/cli/php -r 'функц сложить($a,$b){возврат $a+$b;} функц умножить($a,$b){возврат $a*$b;} эхо сложить(3,умножить(2,4));'
# Функция абсолютного значения
./sapi/cli/php -r 'function absVal($n){return $n<0?-$n:$n;} echo absVal(-7);'
./sapi/cli/php -r 'функц абс($n){возврат $n<0?-$n:$n;} эхо абс(-7);'
# Стрелочная функция с русскими именами
./sapi/cli/php -r '$arr=[1,2,3,4,5]; $res=array_map(fn($x)=>$x*2,$arr); print_r($res);'
./sapi/cli/php -r '$массив=[1,2,3,4,5]; $результат=array_map(фн($x)=>$x*2,$массив); print_r($результат);'
# Функция как callback
./sapi/cli/php -r 'function cube($x){return $x**3;} $arr=[1,2,3]; print_r(array_map("cube",$arr));'
./sapi/cli/php -r 'функц куб($x){возврат $x**3;} $массив=[1,2,3]; print_r(array_map("куб",$массив));'
```
### Вывод
```bash
# echo / эхо
./sapi/cli/php -r 'echo "Hello\n";'
./sapi/cli/php -r 'эхо "Привет\n";'
# print / печать
./sapi/cli/php -r 'print "Hello\n";'
./sapi/cli/php -r 'печать "Привет\n";'
# die / стоп
./sapi/cli/php -r 'die("OK\n");'
./sapi/cli/php -r 'стоп("OK\n");'
```
### Логические константы
```bash
# true / правда
./sapi/cli/php -r 'if(true){ echo "OK\n"; }'
./sapi/cli/php -r 'если(правда){ эхо "OK\n"; }'
# false / ложь
./sapi/cli/php -r 'if(false){ echo "A"; }else{ echo "B\n"; }'
./sapi/cli/php -r 'если(ложь){ эхо "A"; }иначе{ эхо "B\n"; }'
# null / пусто
./sapi/cli/php -r '$x=null; echo is_null($x)?"OK\n":"";'
./sapi/cli/php -r '$x=пусто; эхо is_null($x)?"OK\n":"";'
```
### Классы и ООП
```bash
# class / класс
./sapi/cli/php -r 'class Foo{} echo "OK\n";'
./sapi/cli/php -r 'класс Foo{} эхо "OK\n";'
# new / нов
./sapi/cli/php -r 'class Foo{} $x=new Foo(); echo "OK\n";'
./sapi/cli/php -r 'класс Foo{} $x=нов Foo(); эхо "OK\n";'
# public / публ
./sapi/cli/php -r 'class Foo{public $x=1;} echo "OK\n";'
./sapi/cli/php -r 'класс Foo{публ $x=1;} эхо "OK\n";'
# private / приватн
./sapi/cli/php -r 'class Foo{private $x=1;} echo "OK\n";'
./sapi/cli/php -r 'класс Foo{приватн $x=1;} эхо "OK\n";'
# protected / защищ
./sapi/cli/php -r 'class Foo{protected $x=1;} echo "OK\n";'
./sapi/cli/php -r 'класс Foo{защищ $x=1;} эхо "OK\n";'
# static / статич
./sapi/cli/php -r 'class Foo{static $x=1;} echo Foo::$x;'
./sapi/cli/php -r 'класс Foo{статич $x=1;} эхо Foo::$x;'
# extends / расшир
./sapi/cli/php -r 'class A{} class B extends A{} echo "OK\n";'
./sapi/cli/php -r 'класс A{} класс B расшир A{} эхо "OK\n";'
# implements / реализ
./sapi/cli/php -r 'interface I{} class A implements I{} echo "OK\n";'
./sapi/cli/php -r 'интерфейс I{} класс A реализ I{} эхо "OK\n";'
```
### Исключения
```bash
# try/catch / проб/отлов
./sapi/cli/php -r 'try{ echo "OK\n"; }catch(Exception $e){}'
./sapi/cli/php -r 'проб{ эхо "OK\n"; }отлов(Exception $e){}'
# throw / бросить
./sapi/cli/php -r 'try{ throw new Exception(); }catch(Exception $e){ echo "OK\n"; }'
./sapi/cli/php -r 'проб{ бросить нов Exception(); }отлов(Exception $e){ эхо "OK\n"; }'
# finally / к_проб
./sapi/cli/php -r 'try{ echo "A"; }finally{ echo "B\n"; }'
./sapi/cli/php -r 'проб{ эхо "A"; }к_проб{ эхо "B\n"; }'
# try/catch с message
./sapi/cli/php -r 'try{ throw new Exception("OK\n"); }catch(Exception $e){ echo $e->getMessage(); }'
./sapi/cli/php -r 'проб{ бросить нов Exception("OK\n"); }отлов(Exception $e){ эхо $e->getMessage(); }'
```
### Switch/Match
```bash
# switch / перекл
./sapi/cli/php -r '$x=2; switch($x){case 1: echo "A"; break; case 2: echo "B\n"; break;}'
./sapi/cli/php -r '$x=2; перекл($x){случай 1: эхо "A"; брейк; случай 2: эхо "B\n"; брейк;}'
# case / случай
./sapi/cli/php -r '$x=2; switch($x){case 2: echo "OK\n"; break;}'
./sapi/cli/php -r '$x=2; перекл($x){случай 2: эхо "OK\n"; брейк;}'
# default / по_умолч
./sapi/cli/php -r '$x=99; switch($x){default: echo "OK\n";}'
./sapi/cli/php -r '$x=99; перекл($x){по_умолч: эхо "OK\n";}'
# match / сопостав
./sapi/cli/php -r 'echo match(2){1=>"A",2=>"B"};'
./sapi/cli/php -r 'эхо сопостав(2){1=>"A",2=>"B"};'
```
### Константы и переходы
```bash
# const / конст
./sapi/cli/php -r 'const X=42; echo X;'
./sapi/cli/php -r 'конст X=42; эхо X;'
# goto / переход
./sapi/cli/php -r 'goto label; label: echo "OK\n";'
./sapi/cli/php -r 'переход label; label: эхо "OK\n";'
# yield / отдать
./sapi/cli/php -r 'function gen(){yield 1;} foreach(gen() as $v) echo $v;'
./sapi/cli/php -r 'функц gen(){отдать 1;} д_кажд(gen() как $v) эхо $v;'
# Итоговый комбинированный тест
./sapi/cli/php -r 'function sum($a,$b){return $a+$b;} echo sum(5,3);'
./sapi/cli/php -r 'функц сумма($a,$b){возврат $a+$b;} эхо сумма(5,3);'
```
---
## 🔧 Изменённые файлы
| Файл | Изменения |
|------|-----------|
| `Zend/zend_language_scanner.l` | Русские ключевые слова |
| `Zend/zend_constants.c` | `правда`/`ложь`/`пусто` |
| `Zend/zend_constants.h` | UTF-8 длины (8,10,12) |
---
## 🔨 Сборка
```bash
git clone https://gitlab.com/mzhoot/ru_php.git
cd ru_php
./buildconf --force
./configure --enable-debug --disable-all
make -j$(nproc)
./sapi/cli/php -r 'эхо "Привет, русский PHP!\n";'
```
---
## 📊 Результат тестирования
| Категория | Тестов (оригинал+русский) | Статус |
|-----------|--------------------------|--------|
| Условные операторы | 8 | ✅ |
| Циклы | 14 | ✅ |
| Foreach | 4 | ✅ |
| Функции | 40 | ✅ |
| Вывод | 6 | ✅ |
| Логические константы | 6 | ✅ |
| Классы и ООП | 16 | ✅ |
| Исключения | 8 | ✅ |
| Switch/Match | 8 | ✅ |
| Прочие | 8 | ✅ |
| **ИТОГО** | **118** | **✅ 100%** |
---
## 📝 Лицензия
PHP is distributed under the [Modified BSD License](LICENSE) PHP is distributed under the [Modified BSD License](LICENSE)
(SPDX-License-Identifier: `BSD-3-Clause`). (SPDX-License-Identifier: `BSD-3-Clause`).
[![Test](https://github.com/php/php-src/actions/workflows/test.yml/badge.svg)](https://github.com/php/php-src/actions/workflows/test.yml) **© 2026 - Русский форк PHP** 🇷🇺
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/php.svg)](https://issues.oss-fuzz.com/issues?q=project:php) ```
## Documentation
The PHP manual is available at [php.net/docs](https://www.php.net/docs).
## Installation
### Prebuilt packages and binaries
Prebuilt packages and binaries can be used to get up and running fast with PHP.
For Windows, the PHP binaries can be obtained from
[windows.php.net](https://windows.php.net). After extracting the archive the
`*.exe` files are ready to use.
For other systems, see the [installation chapter](https://www.php.net/install).
### Building PHP source code
*For Windows, see [Build your own PHP on Windows](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2).*
For a minimal PHP build from Git, you will need autoconf, bison, and re2c. For
a default build, you will additionally need libxml2 and libsqlite3.
On Ubuntu, you can install these using:
```shell
sudo apt install -y pkg-config build-essential autoconf bison re2c libxml2-dev libsqlite3-dev
```
On Fedora, you can install these using:
```shell
sudo dnf install re2c bison autoconf make ccache libxml2-devel sqlite-devel
```
On MacOS, you can install these using `brew`:
```shell
brew install autoconf bison re2c libiconv libxml2 sqlite
```
or with `MacPorts`:
```shell
sudo port install autoconf bison re2c libiconv libxml2 sqlite3
```
Generate configure:
```shell
./buildconf
```
Configure your build. `--enable-debug` is recommended for development, see
`./configure --help` for a full list of options.
```shell
# For development
./configure --enable-debug
# For production
./configure
```
Build PHP. To speed up the build, specify the maximum number of jobs using the
`-j` argument:
```shell
make -j4
```
The number of jobs should usually match the number of available cores, which
can be determined using `nproc`.
## Testing PHP source code
PHP ships with an extensive test suite, the command `make test` is used after
successful compilation of the sources to run this test suite.
It is possible to run tests using multiple cores by setting `-jN` in
`TEST_PHP_ARGS` or `TESTS`:
```shell
make TEST_PHP_ARGS=-j4 test
```
Shall run `make test` with a maximum of 4 concurrent jobs: Generally the maximum
number of jobs should not exceed the number of cores available.
Use the `TEST_PHP_ARGS` or `TESTS` variable to test only specific directories:
```shell
make TESTS=tests/lang/ test
```
The [qa.php.net](https://qa.php.net) site provides more detailed info about
testing and quality assurance.
## Installing PHP built from source
After a successful build (and test), PHP may be installed with:
```shell
make install
```
Depending on your permissions and prefix, `make install` may need superuser
permissions.
## PHP extensions
Extensions provide additional functionality on top of PHP. PHP consists of many
essential bundled extensions. Additional extensions can be found in the PHP
Extension Community Library - [PECL](https://pecl.php.net).
## Contributing
The PHP source code is located in the Git repository at
[github.com/php/php-src](https://github.com/php/php-src). Contributions are most
welcome by forking the repository and sending a pull request.
Discussions are done on GitHub, but depending on the topic can also be relayed
to the official PHP developer mailing list internals@lists.php.net.
New features require an RFC and must be accepted by the developers. See
[Request for comments - RFC](https://wiki.php.net/rfc) and
[Voting on PHP features](https://wiki.php.net/rfc/voting) for more information
on the process.
Bug fixes don't require an RFC. If the bug has a GitHub issue, reference it in
the commit message using `GH-NNNNNN`. Use `#NNNNNN` for tickets in the old
[bugs.php.net](https://bugs.php.net) bug tracker.
Fix GH-7815: php_uname doesn't recognise latest Windows versions
Fix #55371: get_magic_quotes_gpc() throws deprecation warning
See [Git workflow](https://wiki.php.net/vcs/gitworkflow) for details on how pull
requests are merged.
### Guidelines for contributors
See further documents in the repository for more information on how to
contribute:
- [Contributing to PHP](/CONTRIBUTING.md)
- [PHP coding standards](/CODING_STANDARDS.md)
- [Internal documentation](https://php.github.io/php-src/)
- [Mailing list rules](/docs/mailinglist-rules.md)
- [PHP release process](/docs/release-process.md)
## Credits
For the list of people who've put work into PHP, please see the
[PHP credits page](https://www.php.net/credits.php).