Skip to content

Instantly share code, notes, and snippets.

View iluuu1994's full-sized avatar

Ilija Tovilo iluuu1994

View GitHub Profile
@iluuu1994
iluuu1994 / README.md
Last active April 15, 2024 10:45
${} string interpolation migration script

Copy the migrator.php file to the root of your project and run the following command:

for file in **/*.php; do php ./migrator.php "$file"; done

BACK UP YOUR REPOSITORY BEFORE RUNNING THIS SCRIPT!

@iluuu1994
iluuu1994 / save_cookie.php
Last active May 12, 2021 15:00
Vanilla sessions with RoadRunner
--TEST--
Named arguments in varargs.
--FILE--
<?php
function dump(...$values): void {
var_dump($values);
}
$p = dump('Foo', ?, bar: 'Bar');
<?php
class Sum {
// Can be modified
public initonly int $lhs;
public initonly int $rhs;
// Should be computed
public initonly int $sum;
<?php
class Point {
public function __construct(
public initonly int $x,
public initonly int $y,
) {}
public function __clone() {
// What to set x/y to?
<?php
class Sum {
public initonly int $sum;
public function __construct(
public initonly int $lhs,
public initonly int $rhs,
) {
$this->sum = $this->lhs + $this->rhs;
// Literal pattern
$foo is 1;
$foo is 'foo';
$foo is SOME_CONST; // Ambiguous with class names :(
// Binding pattern
$foo is $bar;
// Type pattern
$foo is Foo;
<?php
match ($foo) {
is int => ...,
is string|float => ...,
is Foo => ...,
is array => ...,
};
<?php
data class Point(
int $x,
int $y,
);
// Compiles to
class Point {
@iluuu1994
iluuu1994 / enum.php
Last active October 3, 2020 19:22
Enum generation
<?php
enum Foo {
case Bar;
case Baz(int $qux);
}
// Gets compiled to
abstract class Foo