nkkollaw / zubr

Wrapper library to fix inconsistencies in PHP's core functions
MIT License
99 stars 6 forks source link

Fix return types on regex functions #108

Open nkkollaw opened 7 years ago

nkkollaw commented 7 years ago

They were suggesting on Reddit to "fix the return types on those godawful regex functions in PHP" (see https://www.reddit.com/r/PHP/comments/6rnt2p/zubr_wrapper_library_to_fix_inconsistencies_in/dl6knuw/).

Do we want to tackle this, and if yes—when?

Petah commented 7 years ago

What exactly are the inconsistencies?

nkkollaw commented 7 years ago

preg_grep returns array, preg_match returns int and saves matches to array passed by reference.

These are just 2.

Petah commented 7 years ago

So it will be

$matches = preg_match(...);
if (!empty($matches)) {
    // use $matches
}

Instead of

if (preg_match(..., $matches)) {
    // use $matches
}
Petah commented 7 years ago

Also for preg_match_all, is it no longer going to return the count of matches, and now only the matches array?

nkkollaw commented 7 years ago

Yes.