PHPackages                             kozmaoliver/native-methods-fixer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kozmaoliver/native-methods-fixer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kozmaoliver/native-methods-fixer
================================

A fun package that normalizes PHP's inconsistent native function parameter orders

v1.0.1(2w ago)01↓100%MITPHPPHP &gt;=8.2

Since May 21Pushed 2w agoCompare

[ Source](https://github.com/kozmaoliver/php-native-methods-fixer)[ Packagist](https://packagist.org/packages/kozmaoliver/native-methods-fixer)[ RSS](/packages/kozmaoliver-native-methods-fixer/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Native Methods Fixer
====================

[](#native-methods-fixer)

> Just for fun, I don't want to offend anyone. Enjoy!

A whimsical PHP package that fixes the inconsistent parameter ordering in PHP's native functions by providing wrapper functions with consistent signatures.

The Problem
-----------

[](#the-problem)

PHP's native functions have inconsistent parameter ordering:

```
// Needle/haystack are swapped between array and string functions
in_array($needle, $haystack)
strpos($haystack, $needle)

// Callback position varies
array_map($callback, $array)
array_filter($array, $callback)

// Subject position in replacement functions
preg_replace($pattern, $replacement, $subject)
str_replace($search, $replace, $subject)
```

The Solution
------------

[](#the-solution)

This package provides `fixed_*` wrapper functions that consistently place the subject/haystack as the first parameter:

```
use function NativeMethodsFixer\fixed_in_array;
use function NativeMethodsFixer\fixed_strpos;
use function NativeMethodsFixer\fixed_array_map;
use function NativeMethodsFixer\fixed_preg_replace;

// All search functions: haystack first, needle second
fixed_in_array($haystack, $needle)
fixed_strpos($haystack, $needle)

// All array functions: array first, callback second
fixed_array_map($array, $callback)
fixed_array_filter($array, $callback)

// All replacement functions: subject first
fixed_preg_replace($subject, $pattern, $replacement)
fixed_str_replace($subject, $search, $replace)
```

Installation
------------

[](#installation)

```
composer require kozmaoliver/native-methods-fixer
```

Usage
-----

[](#usage)

The functions are automatically available after Composer autoload:

```
