Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: live627 on December 02, 2021, 07:23:49 PM

Title: Polyfill of create_function()
Post by: live627 on December 02, 2021, 07:23:49 PM
[Link to the mod](https://custom.simplemachines.org/index.php?mod=4300)

## Polyfill of `create_function()`

Uncover the grave of [`create_function()`] because some old mods may still use it.

### Manual Installation

This is for if you lose access to the package manager due to an error from a missing [`create_function()`]:
- Copy `Subs-CreateFunction.php` into your sources directory
- Copy `install.php` to the board directory and execute it (remember to delete it afterwards!)
  - Equivalent to running the following PHP code
    ```php
    add_integration_function(
       'integrate_pre_include',
       '$sourcedir/Subs-CreateFunction.php
    ');
    ```

### But I'm not on PHP 8 yet!
Not to worry. It does nothing if the function is already defined. In fact, here, this is the code.
```php
if (!function_exists('create_function'))
{
   function create_function($args, $code)
   {
      return eval(sprintf('return function(%s) {%s};', $args, $code));
   }
}
```

### Public domain
Do whatever you want with this code. Feed it to alligators for all I care.

[`create_function()`]: https://www.php.net/create_function
Title: Re: Polyfill of create_function()
Post by: d3vcho on December 03, 2021, 07:18:36 AM
I successfully fed a group of aligators with your code. They weren't too happy about it.



Good stuff ;)
Title: Re: Polyfill of create_function()
Post by: Arantor on December 29, 2021, 09:53:50 AM
Kind of a shame this wasn't included in 2.0.19.
Title: Re: Polyfill of create_function()
Post by: shadav on May 03, 2022, 01:57:58 PM
thank you for this
starting a new project and all of a sudden my package manager was broken and throwing out some error about create_function()
I remembered this mod so downgraded my php, installed this mod, put php back to 8 and all was right again