Skip to content

Fix(deprecation) Optional parameter declared before required parameter is implicitly treated as a required parameter #365

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/form/sfFormField.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class sfFormField
/**
* Constructor.
*
* @param sfWidgetForm $widget A sfWidget instance
* @param sfFormField $parent The sfFormField parent instance (null for the root widget)
* @param string $name The field name
* @param string $value The field value
* @param sfValidatorError $error A sfValidatorError instance
* @param sfWidgetForm $widget A sfWidget instance
* @param sfFormField|null $parent The sfFormField parent instance (null for the root widget)
* @param string $name The field name
* @param mixed $value The field value
* @param sfValidatorError|null $error A sfValidatorError instance
*/
public function __construct(sfWidgetForm $widget, ?sfFormField $parent = null, $name, $value, ?sfValidatorError $error = null)
public function __construct(sfWidgetForm $widget, ?sfFormField $parent = null, $name = '', $value = null, ?sfValidatorError $error = null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The reason $parent default value was null is because when argument types were introduced in PHP 5.4, the only way to make it nullable was to put the null default value. https://durak.org/sean/pubs/software/php-5.4.6/language.oop5.typehinting.html

To follow the initial intention, you would have to remove the null default value from $parent.

Copy link
Member

Choose a reason for hiding this comment

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

any inputs on this @thirsch ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We thought about that in #365 (comment) and at least in theory it might be a BC if named parameters are in use, which might not be the case at all. I'm fine with both. Let me know your thoughts and I'm happy to provide a pr for it.

{
$this->widget = $widget;
$this->parent = $parent;
Expand Down
12 changes: 6 additions & 6 deletions lib/form/sfFormFieldSchema.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class sfFormFieldSchema extends sfFormField implements ArrayAccess, Iterator, Co
/**
* Constructor.
*
* @param sfWidgetFormSchema $widget A sfWidget instance
* @param sfFormField $parent The sfFormField parent instance (null for the root widget)
* @param string $name The field name
* @param string $value The field value
* @param sfValidatorError $error A sfValidatorError instance
* @param sfWidgetFormSchema $widget A sfWidget instance
* @param sfFormField|null $parent The sfFormField parent instance (null for the root widget)
* @param string $name The field name
* @param mixed $value The field value
* @param sfValidatorError|null $error A sfValidatorError instance
*/
public function __construct(sfWidgetFormSchema $widget, ?sfFormField $parent = null, $name, $value, ?sfValidatorError $error = null)
public function __construct(sfWidgetFormSchema $widget, ?sfFormField $parent = null, $name = '', $value = null, ?sfValidatorError $error = null)
{
parent::__construct($widget, $parent, $name, $value, $error);

Expand Down