core icon indicating copy to clipboard operation
core copied to clipboard

Switching to Enums instead of Entity Classes

Open jyxjjj opened this issue 3 years ago • 3 comments

🎉 Feature Request

⚠️⚠️⚠️ This FR will break backward compatibility.

Summary

FR:

Switching to Enums instead of Entity Classes.

PHP 8.1 supports Enum, But this will break backward compatibility.

Learn from Symfony, we can use

    if (PHP_VERSION_ID < 80100) {
        require_once 'class_of_Update.php';
    } else {
        require_once 'enum_of_Update.php';
    }

Then this framework users can call it like:

if (PHP_VERSION_ID < 80100) {
    echo Update::Message;
} else {
    echo Update::Message->value;
}

To fix backward compatibility.

Don't worry about if code is elegant, framework like Symfony is using polyfills like this.

jyxjjj avatar Aug 08 '22 06:08 jyxjjj

Btw, I think we should not compatible it like this, If your user base doesn’t support 8.1 yet then your project isn’t ready for 8.1. Either that or you need to make the decision to release two versions concurrently, not this mess.

jyxjjj avatar Aug 08 '22 07:08 jyxjjj

Hi @jyxjjj, I'm not sure I understand what the benefit is of changing to enums, could you please explain more?

Also, this project is ready for PHP8.1. It just doesn't use all the PHP8.1 exclusive features.

noplanman avatar Aug 10 '22 14:08 noplanman

Hummm, when i was submit this issue, i didn't think about what the benefit is, Just, i am using this repo, and be confused with:

Update's types is written with Class Consts, but Messages' types are just strings.

Then i thought, Hey the PHP 8.1 had supported Enums, why don't we use it.

So, i submitted this issue.

Benefits that Enums better than Consts can be found everywhere, but now, i think it may not a good idea to you, because you are a completed project. Enums may only show its benefit when writing a new project. It has, but less, for a completed project. And migrating needs more time.

So, you may should consider at your own discretion to migrate or not.

jyxjjj avatar Aug 10 '22 15:08 jyxjjj

Thanks for the feedback @jyxjjj.

I'll close this for now, but we can always come back to this if need be in the future.

noplanman avatar Aug 17 '22 00:08 noplanman