-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
decimal validation rule failed when set strict_types = 1 #52776
base: 11.x
Are you sure you want to change the base?
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
The added tests pass without the string cast. What is the motivation behind the string cast here? |
sorry ,yesterday i forgot to add the descreption |
The following test passes in a fresh Laravel application... <?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Support\Facades\Validator;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$data = Validator::validate(['foo' => 1], ['foo' => 'Decimal:0,1']);
$this->assertSame([
'foo' => 1,
], $data);
}
} |
php info PHP 8.3.10 (cli) (built: Jul 30 2024 13:44:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.10, Copyright (c) Zend Technologies
with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
with Zend OPcache v8.3.10, Copyright (c), by Zend Technologies
some bad case scripts <?php
declare(strict_types=1);
$matches = [];
$value = 1111;
if (preg_match('/^[+-]?\d*\.?(\d*)$/', $value, $matches) !== 1) {
return false;
}
var_dump($value,$matches); output /opt/homebrew/Cellar/php/8.3.10/bin/php /Users/x/x/preg_match.2.php
PHP Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, int given in /Users/x/x/preg_match.2.php:7
Stack trace:
#0 /Users/x/x/preg_match.2.php(7): preg_match('/^[+-]?\\d*\\.?(\\...', 1111, Array)
#1 {main}
thrown in /Users/x/x/preg_match.2.php on line 7
Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, int given in /Users/x/xpreg_match.2.php:7
Stack trace:
#0 /Users/x/x/preg_match.2.php(7): preg_match('/^[+-]?\\d*\\.?(\\...', 1111, Array)
#1 {main}
thrown in /Users/x/x/preg_match.2.php on line 7 |
@noname007, that is because
|
setting
declare(strict_types=1)
will result to a exception throwing at thepreg_match
pos