Not a bug Use ::class instead of class strings

Xon

Well-known member
Affected version
2.2.2
A number of places in the XenForo code base refer to the full class name as a string instead of just sanely using the built in ::class feature, largely around extendClass

Since XenForo 2.1+ now requires a minimum php version which supports this, it would make sense to use this feature consistently. I've noticed it is used on some of the very new XF2.2+ features but hasn't been retrofitted anywhere else.

I'ld even suggest this is probably more useful than the standard practice of \XF::repository('XF:User') and probably should transition to \XF::repository(User::class).
 
The reason I bring it up as a bug; getRepository and other places only check on the short name not the resulting expanded name (if any!) for the cache check, which can result in multiple copies of the same class being created when this is not expected
 
I don't think we're going to make a full proactive pass to change these references at this point, though you may see things change over time (sort of like some of the type hints).

In terms of the repository comment, passing the short name in is what is generally expected here (and I think our code should do that consistently), though it's not entirely clear by the argument name compared to getFinder, for example.
 
Back
Top Bottom