Skip to content

Instantly share code, notes, and snippets.

@thekid
thekid / arrayaccess.diff
Last active December 28, 2025 12:12
Is operator array structure support for ArrayAccess
diff --git a/src/main/php/lang/ast/syntax/php/IsOperator.class.php b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
index 30832b5..bb1048e 100755
--- a/src/main/php/lang/ast/syntax/php/IsOperator.class.php
+++ b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
@@ -250,24 +250,29 @@ class IsOperator implements Extension {
}
return $compound;
} else if ($pattern instanceof IsArrayStructure) {
- $compound= new BinaryExpression(
- new InvokeExpression(new Literal('is_array'), [$init]),
@thekid
thekid / unpack.diff
Created December 28, 2025 10:15
Is operator with binding rest
diff --git a/src/main/php/lang/ast/syntax/php/IsOperator.class.php b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
index 7e34fc1..99c40b3 100755
--- a/src/main/php/lang/ast/syntax/php/IsOperator.class.php
+++ b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
@@ -14,6 +14,7 @@ use lang\ast\nodes\{
MatchExpression,
OffsetExpression,
ScopeExpression,
+ UnpackExpression,
Variable
@thekid
thekid / IsOptional.class.php
Created December 27, 2025 16:52
Is operator with binding defaults using =
<?php namespace lang\ast\syntax\php;
use lang\ast\Type;
use util\Objects;
class IsOptional extends Type {
public $binding, $default;
/**
* Creates a an optional binding "type"
@thekid
thekid / IsOptional.class.php
Created December 27, 2025 16:34
Is operator with binding defaults using ??
<?php namespace lang\ast\syntax\php;
use lang\ast\Type;
use util\Objects;
class IsOptional extends Type {
public $binding, $default;
/**
* Creates a an optional binding "type"
@thekid
thekid / CatchTest.class.php
Created December 27, 2025 16:27
Catch with is operator
<?php namespace lang\ast\syntax\php\unittest;
use lang\ast\unittest\emit\EmittingTest;
use test\{Assert, Test, Values};
class CatchTest extends EmittingTest {
#[Test, Values(['$e', 'IllegalAccessException $e', 'IllegalAccessException|Error $e'])]
public function default_try_with($catch) {
Assert::equals('Test', $this->run('use lang\\IllegalAccessException; class %T {
@thekid
thekid / pdf.script.php
Last active June 22, 2025 11:54
PDF to Markdown
<?php
use com\adobe\pdf\{PdfReader, Content, Ref, Tokens, CharacterMap};
use io\streams\FileInputStream;
use lang\FormatException;
use util\Objects;
use util\cmd\Console;
try {
$reader= new PdfReader(new FileInputStream($argv[1]));
@thekid
thekid / cdp.script.php
Created April 6, 2025 13:21
CDP in PHP
<?php
use io\{File, Files};
use lang\Value;
use peer\http\HttpConnection;
use text\json\{Json, StreamInput};
use util\Comparison;
use util\cmd\Console;
use websocket\WebSocket;
@thekid
thekid / Ws.class.php
Last active January 19, 2025 12:20
Websockets example
<?php
use util\Bytes;
use web\Application;
use web\handler\WebSocket;
class Ws extends Application {
public function routes() {
return [
@thekid
thekid / TestGPT.class.php
Last active November 3, 2024 21:09
ChatGPT REST API
<?php
use com\openai\rest\OpenAIEndpoint;
use io\File;
use util\Objects;
use web\Application;
class TestGPT extends Application {
private $ai;
@thekid
thekid / TestRT.class.php
Last active November 3, 2024 22:08
ChatGPT realtime API inside websocket server
<?php
use com\openai\realtime\RealtimeApi;
use io\streams\LinesIn;
use io\{File, Files};
use util\Objects;
use util\log\Logging;
use web\Application;
class TestRT extends Application {