Skip to content

Instantly share code, notes, and snippets.

@iluuu1994
iluuu1994 / index.php
Last active August 24, 2024 09:49
Relative calls to local functions in top 1000 composer packages
<?php
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Function_;
use PhpParser\ParserFactory;
<?php
data class Vec {
public function __construct(
public $x,
public $y,
) {}
public mutating function double() {
$this->x *= 2;
<?php
class Foo {
public function __get($name, $scope) {
var_dump($scope);
return '';
}
}
$foo = new Foo();
@iluuu1994
iluuu1994 / property-hooks.md
Last active January 25, 2023 13:44
Property Hooks

Property Hooks

Use case 0: Stored property

No change necessary, can be overridden with hooks without changes.

class C {
    public int $prop;
}
@iluuu1994
iluuu1994 / install.sh
Last active October 21, 2022 10:41
GH-9746
#!/bin/bash
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
autoconf \
bison \
ca-certificates \
gcc \
libsqlite3-dev \
libssl-dev \
@iluuu1994
iluuu1994 / asan_ubsan.sh
Created August 13, 2022 18:08
php-src ASAN/UBSAN build
#!/bin/bash
make distclean
./buildconf
./configure --enable-debug CFLAGS="-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-fsanitize=undefined,address"
make -j14
make test TEST_PHP_ARGS="-j14 --asan"
001+ /home/runner/work/php-src/php-src/Zend/zend_types.h:1208:9: runtime error: member access within misaligned address 0xbebebebebebebebe for type 'struct zend_refcounted', which requires 4 byte alignment
001- Exception from valid()
002+ 0xbebebebebebebebe: note: pointer points here
003+ <memory cannot be printed>
004+ /home/runner/work/php-src/php-src/Zend/zend_types.h:1172:2: runtime error: member access within misaligned address 0xbebebebebebebebe for type 'struct zend_refcounted_h', which requires 4 byte alignment
005+ 0xbebebebebebebebe: note: pointer points here
006+ <memory cannot be printed>
007+ AddressSanitizer:DEADLYSIGNAL
008+ =================================================================
009+ ==193472==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55f9e9e0c05e bp 0x7fff4073f150 sp 0x7fff4073f130 T0)
@iluuu1994
iluuu1994 / test.php
Created March 24, 2022 20:16
Accessors for arrays
<?php
class Foo {
public array $bar {
get;
/**
* @param list<string> $path
* @param \Closure(list<string> $path, mixed $value, bool $unset): void $update
*/
update(array $path, mixed $value, bool $unset, \Closure $update) {}
@iluuu1994
iluuu1994 / example.swift
Created March 18, 2022 21:53
Swift setter semantics with value types
import Foundation
class Foo {
var _numbers: [Int] = [42]
var numbers: [Int] {
get { _numbers }
set(value) {
print("Old: ", _numbers)
print("New: ", value)
}
@iluuu1994
iluuu1994 / analysis.php
Created March 17, 2022 16:38
${} analysis in top 1000 packagist repos
<?php error_reporting(E_ALL);
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(__DIR__ . '/sources'),
RecursiveIteratorIterator::LEAVES_ONLY
);
$i = 0;
$totalOption3 = 0;
$totalOption4 = 0;