Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Consistent behaviour between MessageBag constructor and public API #56

Closed
michaeldyrynda opened this issue Apr 18, 2016 · 3 comments
Closed

Comments

@michaeldyrynda
Copy link

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 array), 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 propose to fix the constructor behaviour, which will bring consistency between the constructor and public API of the MessageBag (add) method.

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

@taylorotwell
Copy link
Member

Yeah we should fix this.

@sahilsharma011
Copy link

@taylorotwell If no one is working on this, then I would like to get assigned on this issue.

@taylorotwell
Copy link
Member

If this isn't fixed yet, I'm open to PRs.

taylorotwell pushed a commit to laravel/framework that referenced this issue 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
symfony-splitter pushed a commit to illuminate/support that referenced this issue 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
taylorotwell pushed a commit to illuminate/support that referenced this issue Sep 17, 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants