Skip to content

Extensions POC#192

Open
thekid wants to merge 1 commit into
masterfrom
feature/extensions
Open

Extensions POC#192
thekid wants to merge 1 commit into
masterfrom
feature/extensions

Conversation

@thekid

@thekid thekid commented Jun 20, 2026

Copy link
Copy Markdown
Member

Extensions for any type, including primitives.

Definition

This is what we might parse this from as an idea:

abstract class StringExtensions {
  extension(string) {
    public function length(string $self) => strlen($self);
    public function contains(string $self, string $needle) => false !== strpos($self, $needle);
  }
}

Usage

Single-expression methods are inlined:

$test= "Test";        // Type inferred to string
$test->length();      // emitted inline as: strlen($test) 
$test->contains('e'); // emitted inline as: false !== strpos($test, 'e')

Performance

Obviously, tracking types will mean extra effort.

# Before
Test cases:  1071 succeeded, 9 skipped
Memory used: 12519.15 kB (12573.42 kB peak)
Time taken:  0.294 seconds (0.778 seconds overall)

# After (w/o the "ExtensionsTest" class)
Test cases:  1071 succeeded, 9 skipped
Memory used: 12534.26 kB (12588.54 kB peak)
Time taken:  0.304 seconds (0.793 seconds overall)

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant