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

Typehint className in instantiate method #44

Closed
wants to merge 1 commit into from

Conversation

Valouleloup
Copy link

@Valouleloup Valouleloup commented Apr 27, 2018

I think this was not Typehinted for BC break reasons but since in src/Doctrine/Instantiator/Instantiator.php the method instantiate calls the buildAndCacheFromFactory method where className is Typehinted as string , I don't see in which scenario $className could not be a string.

Moreover, in the interface the $className parameter is already described as string in the annotation.

If we accept classes that implement InstantiatorInterface but don't use a string as parameter (unlikely) then we need to remove the annotation. Right ?

@@ -16,5 +16,5 @@
*
* @throws ExceptionInterface
*/
public function instantiate($className);
public function instantiate(string $className);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a major BC break, as it breaks implementations :-\

Copy link
Author

@Valouleloup Valouleloup Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hence my comment above (PR comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a major BC break, as it breaks implementations

Note: Not with PHP 7.2+.

But then it should have : object return type, which does break implementations (but can be made forward compatible with both Instantiator 1.x and 2.x).

@alcaeus
Copy link
Member

alcaeus commented Apr 27, 2018

If we accept classes that implement InstantiatorInterface but don't use a string as parameter (unlikely) then we need to remove the annotation. Right ?

Why? The interface clearly defines that the $className argument should be a string. Why would it be anything else, and why would we widen the interface or the default implementation for it?

@Valouleloup
Copy link
Author

Why? The interface clearly defines that the $className argument should be a string. Why would it be anything else, and why would we widen the interface or the default implementation for it?>

What is the point saying "It can be a string or it can be not" ?
Then it could have been @param array $className or @param int $className.
Why bother add an annotation if it doesn't give any information on who it must (not should) work ?

@Ocramius
Copy link
Member

The only reason why this doesn't have a type hint is that it was introduced as a PHP 5.x polyfill. If bumping a major version for this particular change made sense, I would do it. For now, the PR simply stays in a limbo 👍

@greg0ire greg0ire changed the base branch from master to 1.4.x November 9, 2020 18:34
@derrabus
Copy link
Member

Closing in favor of #94.

@derrabus derrabus closed this Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants