1

how to win?

PHP 7.2.0, the create_function() is deprecated.

Thanks for your help,

or wait for developers?

Edited and cleared Code

return create_function( '', "
        global $chery_core_version;

        $path = trailingslashit( dirname( __FILE__ ) ) . 'cherry-core.php';

        $data = get_file_data( $path, array(
            'version' => 'Version'
        ) );

        if ( isset( $data['version'] ) ) {
            $version = $data['version'];
        }

        $old_versions = null;

        if ( null !== $chery_core_version ) {
            $old_versions = array_keys( $chery_core_version );
        }

        if ( is_array( $old_versions ) && isset( $old_versions[0] ) ) {
            $compare = version_compare( $old_versions[0], $version, '<' );

            if ( $compare ) {
                $chery_core_version = array();
                $chery_core_version[ $version ] = $path;
            }
        } else {
            $chery_core_version = array();
            $chery_core_version[ $version ] = $path;
        }
    " );
Pradeep
  • 9,667
  • 13
  • 27
  • 34
  • 2
    Just use a closure/anonymous function instead. [Read more](http://php.net/manual/en/functions.anonymous.php) – naththedeveloper May 11 '18 at 07:48
  • and please read about difference between " and ' I fixed it in code you have used ' and in strin \' but you can use ' as string in " ... " – Davit Huroyan May 11 '18 at 08:00
  • 1
    `create_function()` has been deprecated and replaced many versions ago by [anonymous functions](http://php.net/manual/en/functions.anonymous.php). Anonymous functions are safer, faster and more flexible than the old `create_function()`. – axiac May 11 '18 at 10:03
  • Possible duplicate of [PHP 7.2 Function create\_function() is deprecated](https://stackoverflow.com/questions/48161526/php-7-2-function-create-function-is-deprecated) – Tomas Votruba Dec 18 '18 at 01:14
  • There is might help [Function create_function() is Deprecated in PHP 7.2 - How to Migrate?](https://www.tomasvotruba.cz/blog/2018/12/17/function-create-function-is-deprecated-in-php-72-how-to-migrate/) – Tomas Votruba Dec 18 '18 at 01:15

1 Answers1

0

Use anonymous functions instead:

return function () {
    global $chery_core_version;

    $path = trailingslashit(__DIR__) . 'cherry-core.php';

    $data = get_file_data( $path, [
        'version' => 'Version'
    ] );

    if ( isset( $data['version'] ) ) {
        $version = $data['version'];
    }

    $old_versions = null;

    if ( null !== $chery_core_version ) {
        $old_versions = array_keys( $chery_core_version );
    }

    if ( is_array( $old_versions ) && isset( $old_versions[0] ) ) {
        $compare = version_compare( $old_versions[0], $version, '<' );

        if ( $compare ) {
            $chery_core_version = [];
            $chery_core_version[ $version ] = $path;
        }
    } else {
        $chery_core_version = [];
        $chery_core_version[ $version ] = $path;
    }
};
Justinas
  • 41,402
  • 5
  • 66
  • 96