wp-cli / wp-config-transformer

Programmatically edit a wp-config.php file
MIT License
80 stars 25 forks source link

Check if class exists #26

Closed pablo-sg-pacheco closed 4 years ago

pablo-sg-pacheco commented 4 years ago

Isn't it a good idea to check if the class exists?

I didn't get any errors until now but I ended up getting to this ticket for example: https://wordpress.org/support/topic/wpconfigtransformer-class-redeclaration-fatal-error/

And I thought it could be a good idea to check if the class exists in order to prevent possible errors.

Amazing work! See you

schlessera commented 4 years ago

We're using autoloading via Composer throughout WP-CLI and this library, so there's no need for class_exists() checks.

However, I've just read through that support ticket you've linked, and it seems that both Duplicator and this library fail to use either a namespace or a proper prefix.

While this is worse for a plugin than it is for WP-CLI, I'll look at namespacing our library in a major version bump from our side anyway.

I'll close this PR, as I don't think the class_exist() check does much. It will just move from the redeclaration fatal to a different fatal when it is actually needed, as the actual implementation of both classes is different. So one of them will break either way, even with the checks.

But I'll open a new issue to namespace the library here in a future update.

Thanks anyway for your effort, it is much appreciated, even though the PR is not merged!

pablo-sg-pacheco commented 4 years ago

No problem :) Ok, namespacing seems like a good idea