Repository: codeigniter4/CodeIgniter4 (PHP)

Issue:
Bug: Errors displayed in wrong order when using Validation:SetRule
### PHP Version

7.4, 8.0, 8.1, 8.2

### CodeIgniter4 Version

4.3.1

### CodeIgniter4 Installation Method

Composer (using `codeigniter4/appstarter`)

### Which operating systems have you tested for this bug?

macOS, Windows

### Which server did you use?

apache

### Database

_No response_

### What happened?

When using many SetRule from Validation service in order :
```php
$validation->setRule('username', 'Username', 'required');
```
Then 
```php
$validation->setRule('password', 'Password', 'required');
```

Errors are shown in reverse order.
("Password error" then "Username error")



### Steps to Reproduce

When using many SetRule from Validation service like that :
```php
$validation = \Config\Services::validation();
$validation->setRule('username', 'Username', 'required');
$validation->setRule('password', 'Password', 'required');
if ($this->validation->withRequest($this->request)->run()) {...}
```

Submit your form and show errors in view with :
`<?= validation_list_errors() ?>`

### Expected Output

"Username error"
then 
"Password error" 

### Anything else?

The problem seems to be in Validation/Validation.php line 446
When I replace :
```php
$this->setRules($ruleSet + $this->getRules(), $this->customErrors);
```
By : 
```php
$this->setRules($this->getRules() + $ruleSet, $this->customErrors);
```

It's in the right order (but may cause other problem).


Discussion:
I send PR #7149



Patch:
diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php
index 41aaa4a098fb..c22f38ae2413 100644
--- a/system/Validation/Validation.php
+++ b/system/Validation/Validation.php
@@ -443,7 +443,7 @@ public function setRule(string $field, ?string $label, $rules, array $errors = [
             $ruleSet[$field]['errors'] = $errors;
         }
 
-        $this->setRules($ruleSet + $this->getRules(), $this->customErrors);
+        $this->setRules(array_merge($this->getRules(), $ruleSet), $this->customErrors);
 
         return $this;
     }


Test patch:
diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php
index 6597866b3f88..2c6d52337fe9 100644
--- a/tests/system/Validation/ValidationTest.php
+++ b/tests/system/Validation/ValidationTest.php
@@ -102,6 +102,27 @@ public function testSetRuleStoresRule()
         ], $this->validation->getRules());
     }
 
+    public function testSetRuleMultipleWithIndividual()
+    {
+        $this->validation->setRule('username', 'Username', 'required|min_length[3]');
+        $this->validation->setRule('password', 'Password', ['required', 'min_length[8]', 'alpha_numeric_punct']);
+
+        $this->assertSame([
+            'username' => [
+                'label' => 'Username',
+                'rules' => 'required|min_length[3]',
+            ],
+            'password' => [
+                'label' => 'Password',
+                'rules' => [
+                    'required',
+                    'min_length[8]',
+                    'alpha_numeric_punct',
+                ],
+            ],
+        ], $this->validation->getRules());
+    }
+
     public function testSetRuleAddsRule()
     {
         $this->validation->setRules([
@@ -113,14 +134,14 @@ public function testSetRuleAddsRule()
         $this->validation->setRule('foo', null, 'foo|foz');
 
         $this->assertSame([
-            'foo' => [
-                'label' => null,
-                'rules' => 'foo|foz',
-            ],
             'bar' => [
                 'label' => null,
                 'rules' => 'bar|baz',
             ],
+            'foo' => [
+                'label' => null,
+                'rules' => 'foo|foz',
+            ],
         ], $this->validation->getRules());
     }
 
@@ -142,6 +163,24 @@ public function testSetRuleOverwritesRule()
         ], $this->validation->getRules());
     }
 
+    public function testSetRuleOverwritesRuleReverse()
+    {
+        $this->validation->setRule('foo', null, 'foo|foz');
+        $this->validation->setRules([
+            'foo' => [
+                'label' => null,
+                'rules' => 'bar|baz',
+            ],
+        ]);
+
+        $this->assertSame([
+            'foo' => [
+                'label' => null,
+                'rules' => 'bar|baz',
+            ],
+        ], $this->validation->getRules());
+    }
+
     /**
      * @dataProvider setRuleRulesFormatCaseProvider
      *