Skip to content

Commit 77a67d0

Browse files
committed
docs: update sample code
The value to be validated is not necessarily a string.
1 parent c475127 commit 77a67d0

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

user_guide_src/source/libraries/validation/034.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class MyRules
44
{
5-
public function even(string $str): bool
5+
public function even($value): bool
66
{
7-
return (int) $str % 2 === 0;
7+
return (int) $value % 2 === 0;
88
}
99
}

user_guide_src/source/libraries/validation/035.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
class MyRules
44
{
5-
public function even(string $str, ?string &$error = null): bool
5+
public function even($value, ?string &$error = null): bool
66
{
7-
if ((int) $str % 2 !== 0) {
7+
if ((int) $value % 2 !== 0) {
88
$error = lang('myerrors.evenError');
99

1010
return false;

user_guide_src/source/libraries/validation/037.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
class MyRules
44
{
5-
public function required_with($str, string $fields, array $data): bool
5+
public function required_with($value, string $params, array $data): bool
66
{
7-
$fields = explode(',', $fields);
7+
$params = explode(',', $params);
88

99
// If the field is present we can safely assume that
1010
// the field is here, no matter whether the corresponding
1111
// search field is present or not.
12-
$present = $this->required($str ?? '');
12+
$present = $this->required($value ?? '');
1313

1414
if ($present) {
1515
return true;
@@ -20,7 +20,7 @@ public function required_with($str, string $fields, array $data): bool
2020
// as $fields is the lis
2121
$requiredFields = [];
2222

23-
foreach ($fields as $field) {
23+
foreach ($params as $field) {
2424
if (array_key_exists($field, $data)) {
2525
$requiredFields[] = $field;
2626
}

0 commit comments

Comments
 (0)