An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

XP static initializer blocks
============================

[![Build status on GitHub](https://github.com/xp-lang/xp-static/workflows/Tests/badge.svg)](https://github.com/xp-lang/xp-static/actions)
[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)
[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)
[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)
[![Latest Stable Version](https://poser.pugx.org/xp-lang/xp-static/version.svg)](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)