-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] FormInterface::getPropertyPath() return type incosistency #24560
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
Labels
Comments
Should we update the interface, or maybe change the behaviour when retuning null WDYT ? |
<?php
namespace App\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class IndexController extends AbstractController
{
/**
* @Route(name="index")
* @Template()
*/
public function indexAction()
{
$form = $this->get('form.factory')
->createNamedBuilder('')
->add('text', TextType::class)
->getForm();
return [
'form' => $form->createView(),
];
}
} <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome!</title>
</head>
<body>
<form name="" method="post">
<label for="text">Text</label>
<input type="text" id="text" name="text">
</form>
</body>
</html> We cannot change this behaviour, obviously. |
fabpot
added a commit
that referenced
this issue
Nov 5, 2017
…sov) This PR was merged into the 2.7 branch. Discussion ---------- [Form] Nullable FormInterface::getPropertyPath() | Q | A | ------------- | --- | Branch? | 4.0 | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24560 | License | MIT | Doc PR | `Symfony\Component\Form\Form::getPropertyPath()` returns `null` when the form has an empty name. It allows for unprefixed children. ```php <?php namespace App\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\TextType; class IndexController extends AbstractController { /** * @route(name="index") * @template() */ public function indexAction() { $form = $this->get('form.factory') ->createNamedBuilder('') ->add('text', TextType::class) ->getForm(); return [ 'form' => $form->createView(), ]; } } ``` ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Welcome!</title> </head> <body> <form name="" method="post"> <label for="text">Text</label> <input type="text" id="text" name="text"> </form> </body> </html> ``` But the return type of the `Symfony\Component\Form\FormInterface::getPropertyPath()` is not nullable. We cannot change the behaviour, obviously. At least it's useful in API controllers. So I decided to change the doc block of the interface. Commits ------- d56632a FormInterface::getPropertyPath(): PropertyPathInterface|null
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
In FormInterface::getPropertyPath() the return type is not nullable.
But its implementation in Form::getPropertyPath() actually returns null. This costed me a
Call to a member function getElements() on null
since I was relying on IDE autocomplete.The text was updated successfully, but these errors were encountered: