https://github.com/xp-lang/xp-static
XP static initializer blocks
https://github.com/xp-lang/xp-static
initializer php7 php8 xp-compiler
Last synced: about 2 months ago
JSON representation
XP static initializer blocks
- Host: GitHub
- URL: https://github.com/xp-lang/xp-static
- Owner: xp-lang
- Created: 2021-12-19T13:40:46.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-01T08:03:00.000Z (over 1 year ago)
- Last Synced: 2025-06-27T18:07:57.486Z (9 months ago)
- Topics: initializer, php7, php8, xp-compiler
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
XP static initializer blocks
============================
[](https://github.com/xp-lang/xp-static/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/xp-static)
Plugin for the [XP Compiler](https://github.com/xp-framework/compiler/) which adds a static initializer syntax for PHP. This is compiled to `__static()` functions recognized by the XP class loading mechanism.
Example
-------
```php
namespace com\example\brotli;
class Streams {
static {
stream_wrapper_register('brotli', self::class);
}
// ...
}
```
Installation
------------
After installing the XP Compiler into your project, also include this plugin.
```bash
$ composer require xp-framework/compiler
# ...
$ composer require xp-lang/xp-static
# ...
```
No further action is required.
See also
--------
* [PHP RFC: Static Constructors](https://wiki.php.net/rfc/static_constructor) - 2024
* [PHP RFC: Static Class Constructor](https://wiki.php.net/rfc/static_class_constructor) - 2015
* [Class static initialization block @ PHP Internals (2021)](https://externals.io/message/116031)
* [Class static initialization blocks @ V8.dev](https://v8.dev/features/class-static-initializer-blocks)
* [Static constructor @ PHP Internals (2015)](https://externals.io/message/84602)
* [Static Constructors (C# Programming Guide)](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors)