u/exakat

The Secret Life of "Magic Null" in PHP
▲ 16 r/PHP

The Secret Life of "Magic Null" in PHP

Some situations where you can use NULL instead of 0, or no arguments and it provides a nice feature that you could use every day.

exakat.io
u/exakat — 1 day ago
▲ 7 r/PHP

A modern PHP extension to give preg_ an object-oriented API: feedback wanted!

Hi r/PHP,

preg\_match($pattern, $subject, $matches) has been quietly aging since PHP 3. It still works great, and if you've ever had to explain to a junior dev why the function returns 1, 0, or false, and why the actual result shows up in a variable you passed by reference three arguments ago, you know the classic rear-guard battles you need to fight.

So I built ext/regex: a PHP extension, with C, that wraps the same PCRE2 engine PHP already uses, but behind an immutable, typed, exception-throwing OOP API instead of the sentinel-value soup we have today.

Nothing about preg_* is being removed or deprecated. This is an additive, opt-in sibling API: think of it as DateTime next to strtotime().

Before:

`` if (preg_match('/^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$/', $s, $m) === false) {

// was it "no match" or "regex engine error"? guess!

} ``

After:

`` $m = Regex::of('/^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$/')->match($s);

echo $m->group('year')->value; ``

A few things it fixes: one consistent return type per method (no more int|false roulette), matches as real objects instead of a &$matches out-parameter, exceptions instead of false + preg\_last\_error(), Regex::withLiteral() for safe interpolation, and compile-once/reuse pattern objects.

So far, 34 tests back it up, including a full port of ext/pcre's own test suite. It's installable via PIE: no PECL package, let's be modern; PIE is where extension packaging is heading.

🙋 This is where you come in. I've stared at this API long enough that I can't tell if it's genuinely better or if I've Stockholm-syndromed myself into liking my own method names. Reply below or open an issue/PR: a single "this method name is dumb, call it X" is worth more than an upvote.

👉 Repo: https://github.com/dseguy/regex

u/exakat — 26 days ago
▲ 0 r/PHP

Less Arguments In Child Method

Pop quizz PHP for Friday evening :

how can you remove an argument from a method, between a parent and a child?

#phptip #phptrick

&lt;?php

class x {
    function foo(int $a, string $c, string ...$b) {}
}

// OK
class y extends x {
    function foo(int $a, string ...$b) {}
}
php-tips.readthedocs.io
u/exakat — 1 month ago
▲ 0 r/PHP

The unreachable method

So, it seems that it is possible to paint oneself in a corner and write an unreachable method. How would you call A::foo() in this code below?

Come on, #PHP, there must be something here. #phptip #phptrick

&lt;?php

abstract class A {
    private function foo() { print __CLASS__; }
}

abstract class B extends A {
    private function foo() { print __CLASS__; }
}

class C extends B {
    private function foo() { print __CLASS__; }
    
    public function goo() {
        parent::foo();
        a::foo();
    }
}

($c = new C)-&gt;foo();
$c-&gt;goo();

https://php-tips.readthedocs.io/en/latest/tips/unreachable_method.html

reddit.com
u/exakat — 2 months ago
▲ 0 r/PHP

PHP and AI : what actually exists at the language level

We hear a lot about coding PHP with AI, and PHP calling remote API to query them.

And there are tools maturing quickly in the ecosystem: transformers, home made LLM, FFI libraries and even Rasmus himself creating an extension to run models from within PHP.

So much new ideas poping up!

https://www.exakat.io/php-and-ai-what-actually-exists-at-the-language-level/

u/exakat — 2 months ago
▲ 75 r/PHP

Take The State of PHP 2026 Survey

The Fundatation Survey for 2026 is on: take a moment to ask yourself important #PHP questions, and contribute your observation with the community and the fundation.

surveys.jetbrains.com
u/exakat — 2 months ago