Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine\Common\Util\ClassUtils being deprecated #867

Open
TerjeBr opened this issue Mar 13, 2019 · 21 comments
Open

Doctrine\Common\Util\ClassUtils being deprecated #867

TerjeBr opened this issue Mar 13, 2019 · 21 comments

Comments

@TerjeBr
Copy link

TerjeBr commented Mar 13, 2019

In my application I am using the latest doctrine 2.x. Recently we found it necessary to also use the static function Doctrine\Common\Util\ClassUtils::getRealClass(string $class). But this function is marked as deprecated.

I asked in issue 826 what would be the alternative function to use. Then I got the response that there is no alternative to that function in doctrine 2.x.

This issue is about removing those depreaction notices, since I see no point in marking something as deprecated when the application programmers have nothing to replace it with.

See also comment #826 (comment)

@TerjeBr
Copy link
Author

TerjeBr commented Mar 13, 2019

@Ocramius You said "If you want, you can make ClassUtils::getRealClass() proxy through to the new API in 3.x, and then we can drop it in 4.x."

Does that mean making it not deprecated in 2.x, adding a proxy for it in 3.x (which will be deprecated from the start) and then drop it in 4.x ?

If that is so, that is exactly the kind of change I wanted.

@Ocramius
Copy link
Member

Ocramius commented Mar 13, 2019 via email

@TerjeBr
Copy link
Author

TerjeBr commented Mar 13, 2019

"is deprecated" and "remove the warning" sounds like an oxymoron to me. But as long as we agree that the deprecation warning should go in 2.x, I guess we are on the same page.

@Ocramius
Copy link
Member

Ocramius commented Mar 13, 2019 via email

@TerjeBr
Copy link
Author

TerjeBr commented Mar 13, 2019

Doctrine\Common\Util\ClassUtils starts with

/**
 * Class and reflection related functionality for objects that
 * might or not be proxy objects at the moment.
 *
 * @author Benjamin Eberlei <[email protected]>
 * @author Johannes Schmitt <[email protected]>
 *
 * @deprecated The ClassUtils class is deprecated.
 */
class ClassUtils
{

The annotation @deprecated triggers warnings in f.ex. PHPStorm and other smart editors.

My suggestion is that we remove the @deprecated annotation in 2.x. You may still have a comment in header that this class is/will be deprecated, but without the annotation.

Does that sound ok?

@Ocramius
Copy link
Member

Ocramius commented Mar 13, 2019 via email

@TerjeBr
Copy link
Author

TerjeBr commented Mar 13, 2019

As I said, the annotation has effects in my programming environment.

When I see something marked as deprecated, I always want to replace it. But it does not make sense to mark it as deprecated, when it is no sensible action the application programmer can do to replace it.

@Ocramius
Copy link
Member

Ocramius commented Mar 13, 2019 via email

@TerjeBr
Copy link
Author

TerjeBr commented Mar 13, 2019

So, my original problem is that I have an object that may or may not be a proxy.
First we tried get_class($object) but that failed when the object was proxy instead of the real object.
Then we changed it to Doctrine\Common\Util\ClassUtils::getClass($object).

So, you are saying that the correct way to do it will be:

$em = $this->getDoctrineEntityManager();
$classname = $em->getClassMetadata(get_class($object))->getName();

@Ocramius
Copy link
Member

Ocramius commented Mar 13, 2019 via email

@TerjeBr
Copy link
Author

TerjeBr commented Mar 14, 2019

That is a bit complicated replacement. I guess I will need to make my own Util function to contain that then.

Yes, I guess it would help if that was documented in the class where the @deprecated annotation is.

@Ocramius
Copy link
Member

Ocramius commented Mar 14, 2019 via email

@TerjeBr
Copy link
Author

TerjeBr commented Mar 14, 2019

Ok, have to go now. May be tomorrow or over the weekend.

@TerjeBr
Copy link
Author

TerjeBr commented Mar 14, 2019

Could it also be a new method in the EntityManager?
May be something like $em->getClassName($object);

@Ocramius
Copy link
Member

Ocramius commented Mar 14, 2019 via email

@stof stof closed this as completed Mar 14, 2019
@stof stof reopened this Mar 14, 2019
@stof
Copy link
Member

stof commented Mar 14, 2019

AFAICT, you cannot implement your plan of making the same API available for 3.x: the proxy classname logic is configurable in ProxyManager, so you will need the EntityManager to get the actual configuration, which a static method cannot do.

So we should suggest the metadata-based call as a replacement instead, for people to migrate.

@Ocramius
Copy link
Member

@stof for the 99% of scenarios, assuming the default inflector will be sufficient. For an endpoint that is going to be deprecated, this is acceptable IMO.

@malarzm
Copy link
Member

malarzm commented Mar 14, 2019

There's still a chance it'll break for folks using it in 3.x though

@Ocramius
Copy link
Member

Yes, that is acceptable though, IMO. Can also document it to explain that.

@akomm
Copy link

akomm commented Nov 8, 2019

Is it actually safe to test for Proxy interface (doctrine common) and then \get_parent_class ?

@Ocramius
Copy link
Member

Ocramius commented Nov 8, 2019

That's a valid solution, but the proxy interface changes in ORM 3.x and ODM 2.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants