8000 allow containing 0 or similar values except null. by scil · Pull Request #26095 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

allow containing 0 or similar values except null. #26095

New issue 8000

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

Closed
wants to merge 2 commits into from
Closed

allow containing 0 or similar values except null. #26095

wants to merge 2 commits into from

Conversation

scil
Copy link
@scil scil commented Feb 8, 2018

otherwise, ' 0, false, [] are not be allowed with $containter->set()'.

Q A
Branch? 4.0
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes/no
Tests pass? yes
License MIT
Doc PR

otherwise, doc maybe add words like ' 0, false, [] are not be used with $containter->set()'.
@stof
Copy link
Member
stof commented Feb 8, 2018

Setting anything else than an object should be forbidden anyway and very likely to break (they should be stored as parameters)

Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Looks legit to me, does no harm, for 3.4

@@ -542,7 +542,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_
if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $invalidBehavior) {
return parent::get($id, $invalidBehavior);
}
if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
if (!is_null($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE))) {
Copy link
Member

Choose a reason for hiding this comment

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

if (null !== $service = parent::g...

Sorry, something went wrong.

Copy link
Author

Choose a reason for hiding this comment

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

wonderful

@scil
Copy link
Author
scil commented Feb 9, 2018

I'm develping with swoole, such as LaravelFly, WebSocketFly.

In WebSocketFly, I use symfony/dependency-injection and make a containter for each worker process.
I tried inject worker id and failed, because worker id maybe 0.

public function onWorkerStart(\swoole_server $server, int $workerid)
{
    $workerContainer = clone $serverContainer; // fake code
    $workerContainer->set('id',$workerid); // set an interger value  [0, )
}

https://github.com/scil/WebSocketFly/blob/e54ab563f1bda45cc28172715c9c3e2c70c13cbb/src/WebSocketFly/Server.php#L131

@xabbuh
Copy link
Member
xabbuh commented Feb 9, 2018

Setting anything else than an object should be forbidden anyway and very likely to break (they should be stored as parameters)

@stof while I agree with you for Symfony < 4.1 this would break the new ContainerBag which was introduced in #25288 (which makes me think that #25288 actually breaks the contract specified by the ContainerInterface 🤔).

@scil scil closed this Feb 9, 2018
@nicolas-grekas
Copy link
Member

@xabbuh WDYT? Which part of the contract?
@scil did you close on purpose?

@xabbuh
Copy link
Member
xabbuh commented Feb 9, 2018

ContainerInterface::get() demands to return an object which is not (necessarily) the case for parameters, right? Our interfaces differs from the PSR-11 one here.

@jvasseur
Copy link
Contributor
jvasseur commented Feb 9, 2018

@xabbuh that's not true, ContainerInterface::get() has a return type of mixed allowing anything to be stored in the container.

@jvasseur
Copy link
Contributor
jvasseur commented Feb 9, 2018

Oh, I thought you where speaking of the PSR-11 ContainerInterface, not the Symfony one.

So #25288 doesn't breaks the ContainerInterface contract since it extends the PSR-11 interface and not the Symfony one.

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Feb 9, 2018

@xabbuh actually that's only a non-enforced docblock; nothing anywhere prevents returning anything else in practice. And it is also trivial to use regular configuration to return a non object: just use a factory (I used this recently :) )

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
0