Last active
June 24, 2016 09:18
-
-
Save webdevilopers/8b7e874340823278ffcbe7face9517d2 to your computer and use it in GitHub Desktop.
Using PHP7 type hinting with Symfony Form Text Type and empty_data returning NULL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ChangeInspectionDetailsCommand | |
{ | |
public $problemNumber = ''; // no effect | |
public function problemNumber() | |
{ | |
return (string) $this->problemNumber; // workaround 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ChangeInspectionDetailsHandler | |
{ | |
public function handle(ChangeInspectionDetailsCommand $command) | |
{ | |
// ... | |
$contract->changeInspectionDetails( | |
#$command->problemNumber() // no effect | |
(string) $command->problemNumber() // workaround 2 | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Contract | |
{ | |
public $problemNumber = ''; // no effect | |
public function changeInspectionDetails( | |
string $problemNumber = '' | |
) { | |
$this->problemNumber = $problemNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related issue: webdevilopers/php-ddd#18