dto icon indicating copy to clipboard operation
dto copied to clipboard

PHP 7.2: ERROR: Function create_function() is deprecated

Open guychouk opened this issue 6 years ago • 4 comments

Hey fireproofsocks, I just ran into an issue with DTO when using PHP 7.2 and the JsonDecoder class: ERROR: Function create_function() is deprecated

The error stems from this method in JsonDecoder:

     /**
     * @inheritdoc
     */
    public function decodeFile($filepath)
    {
        // https://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php
        set_error_handler(
            create_function(
                '$severity, $message, $file, $line',
                'throw new \Dto\Exceptions\JsonDecodingException($message, $severity);'
            )
        );
        $content = file_get_contents($filepath);
        restore_error_handler();
        return $this->decodeString($content);
    }

After a bit of research, I found this question on SO, so the fix seems to be pretty straightforward.

I created a pull request for this issue, just wanted to properly document it as well.

Thank you so much for the package, it's amazing.

guychouk avatar Dec 26 '18 09:12 guychouk

Been nearly a year with no love. Somebody may have to take over !

MattWohler avatar Feb 17 '19 04:02 MattWohler

@MattWohler Couldn't agree more, I've already forked this repository and fixed it locally for a project I'm working on, perhaps I could give it a shot.

guychouk avatar Feb 18 '19 09:02 guychouk

@cudacoder If you would continue best OS practices such as tests and Build CI, I would make the switch.

MattWohler avatar Feb 19 '19 19:02 MattWohler

Sorry, this has been completely off my radar: anyone who wishes to take over is welcome to it.

fireproofsocks avatar Apr 01 '21 00:04 fireproofsocks