https://github.com/xp-lang/php-compact-methods
Compact methods for PHP
https://github.com/xp-lang/php-compact-methods
arrow-functions compact compiler-plugin php7 php8 xp-compiler xp-framework
Last synced: 5 days ago
JSON representation
Compact methods for PHP
- Host: GitHub
- URL: https://github.com/xp-lang/php-compact-methods
- Owner: xp-lang
- Created: 2019-09-09T21:34:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-05-29T11:03:04.000Z (10 months ago)
- Last Synced: 2025-10-11T14:11:27.196Z (5 months ago)
- Topics: arrow-functions, compact, compiler-plugin, php7, php8, xp-compiler, xp-framework
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
Compact methods for PHP
=======================
[](https://github.com/xp-lang/php-compact-methods/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagist.org/packages/xp-lang/php-compact-methods)
Plugin for the [XP Compiler](https://github.com/xp-framework/compiler/) which adds compact methods to the PHP language.
Example
-------
Compact methods use the `fn` keyword, much like [PHP 7.4 arrow functions](https://wiki.php.net/rfc/arrow_functions_v2). The RFC suggests this in its *Future Scope* section.
```php
class Person {
private $name;
public fn name(): string => $this->name;
}
```
Installation
------------
After installing the XP Compiler into your project, also include this plugin.
```bash
$ composer require xp-framework/compiler
# ...
$ composer require xp-lang/php-compact-methods
# ...
```
No further action is required.
See also
--------
* https://wiki.php.net/rfc/single-expression-functions
* https://wiki.php.net/rfc/short-functions
* https://wiki.php.net/rfc/arrow_functions_v2#allow_arrow_notation_for_real_functions
* https://github.com/xp-framework/rfc/issues/241