Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using PHP7 type hinting with Symfony Form Text Type and empty_data returning NULL
<?php
class ChangeInspectionDetails extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('problemNumber', TextType::class, [
'empty_data' => '' // no effect
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ChangeInspectionDetailsCommand::class
]);
}
}
<?php
class ChangeInspectionDetailsCommand
{
public $problemNumber = ''; // no effect
public function problemNumber()
{
return (string) $this->problemNumber; // workaround 1
}
}
<?php
class ChangeInspectionDetailsHandler
{
public function handle(ChangeInspectionDetailsCommand $command)
{
// ...
$contract->changeInspectionDetails(
#$command->problemNumber() // no effect
(string) $command->problemNumber() // workaround 2
);
}
}
<?php
class Contract
{
public $problemNumber = ''; // no effect
public function changeInspectionDetails(
string $problemNumber = ''
) {
$this->problemNumber = $problemNumber;
}
}
@webdevilopers
Copy link
Author

webdevilopers commented Jun 24, 2016

Related issue: webdevilopers/php-ddd#18

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