8000 [HttpFoundation] [DX] Add has() function to Request · Issue #17657 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] [DX] Add has() function to Request #17657

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

Closed
ghost opened this issue Feb 2, 2016 · 6 comments
Closed

[HttpFoundation] [DX] Add has() function to Request #17657

ghost opened this issue Feb 2, 2016 · 6 comments

Comments

@ghost
Copy link
ghost commented Feb 2, 2016

Currently you can do this:

$example = $request->get('example');

But you are not able to do this:

if($request->has('example')) {
  // ...
}

I think this should be added to the Request class:

public function has($key)
{
   return $this->attributes->has($key) || $this->query->has($key) || $this->request->has($key);
}
@xabbuh
Copy link
Member
xabbuh commented Feb 2, 2016

I am 👎 on this. Using the get() method usually isn't a good idea as it checks one bag after another. You should rather use one of the concrete parameter bags which already offer the has() method.

@ghost
Copy link
Author
ghost commented Feb 2, 2016

@xabbuh In this case we should deprecate get().
But if we do not deprecate it I think we should add has().

@xabbuh
Copy link
Member
xabbuh commented Feb 2, 2016

I would be fine with deprecating get().

@xabbuh
Copy link
Member
xabbuh commented Feb 2, 2016

However, please note that we already discourage from using this method in its docblock:

This method is mainly useful for libraries that want to provide some flexibility. If you don't need the flexibility in controllers, it is better to explicitly get request parameters from the appropriate public property instead (attributes, query, request).

@fabpot
Copy link
Member
fabpot commented Feb 2, 2016

Closing as adding has won't be done and using get is already discouraged in the phpdocs.

@fabpot fabpot closed this as completed Feb 2, 2016
@ghost
Copy link
Author
ghost commented Feb 3, 2016

@fabpot Shouldn't we fully deprecate it?

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

No branches or pull requests

2 participants
0