Skip to content
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

[5.2] Make MessageBag constructor consistent with add method #13196

Closed
wants to merge 1 commit into from
Closed

[5.2] Make MessageBag constructor consistent with add method #13196

wants to merge 1 commit into from

Conversation

michaeldyrynda
Copy link
Contributor

@michaeldyrynda michaeldyrynda commented Apr 18, 2016

Currently, the behaviour between initialising a new MessageBag and using the add method is inconsistent.

The add method tests for uniqueness (of the key, and the message in the keyed bag), whereas the constructor will accept duplicate messages.

$messageBag = new MessageBag(['messages' => ['first', 'second', 'third', 'third']]);

// $messageBag->getMessages()
// ['messages' => ['first', 'second', 'third', 'third']]

$messageBag = new MessageBag;
$messageBag->add('messages', 'first');
$messageBag->add('messages', 'second');
$messageBag->add('messages', 'third');
$messageBag->add('messages', 'third');

// $messageBag->getMessages()
// ['messages' => ['first', 'second', 'third']

I'm not certain if this is on purpose, so I have opened a PR with a failing test to demonstrate the proposed behaviour, which will amend should the desire exist to match the behaviour between the constructor and public API of the MessageBag class.

It appears this has been around since January, 2013, so this would likely be targeted to next release due to backwards compatibility breakage.

@GrahamCampbell GrahamCampbell changed the title [Proposal] Make MessageBag constructor consistent with add method [5.2] Make MessageBag constructor consistent with add method Apr 18, 2016
@GrahamCampbell
Copy link
Member

Will need to go to 5.3, yes.

@GrahamCampbell
Copy link
Member

Please discuss proposals in the correct place as per the contribution guidelines.

taylorotwell pushed a commit that referenced this pull request Mar 12, 2018
…3485)

* Make MessageBag constructor behaviour consistent with `add`

Addresses laravel/ideas#56 and the (long-closed) #13196.

This change in constructor behaviour aims to bring consistency with the
public `add` method on the MessageBag class, which would prevent
duplicate values in any given MessageBag's key.

* update test to show consistency of behaviour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants