-
Notifications
You must be signed in to change notification settings - Fork 1.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
Bug: Incorrect type that fails strict_types=1 #3610
Comments
I think these are both good changes. Could you submit a PR with these so we can review and merge? |
Personally I would rather stay with Are you sure this is about |
I have just downloaded the latest 2020-09-06 - Build:473a8f5 and prefixed "Strict_types=1" into 450 PHP files. The errors are eliminated when the two suggested modifications are made in accordance with the PHP Manual. I believe that NULL should not be used because PHP 8.0 is imminent and conforming to strict_types will most probably be essential when trying to apply Just in Time compilation. Perhaps a thread could be raised and hopefully a knowlegeable user will be able to suggest a valid reason rather than speculation. Regarding "Personally I would rather stay with null as default... " - may I suggest adding strict_types to your source files. I was amazed to discover that "ini_set('display_errors', 1)" and "ini_set('display_errors', TRUE)" both raised a errors!!! |
I'm not claiming you're wrong, but maybe you could try to change only this line |
I just tried your suggestion and delighted to say it works. There are now two solutions and I do think your solution is a lot simpler. Which solution to raise a PR? |
Thanks for checking it out. Personally, I always think simpler is better. |
<?php declare(strict_types=1); ?>
I have prefixed every system PHP file with the above script and encountered the following two anomalies:
// INCORRECT SCRIPT
./system/HTTP/RequestInterface.php -> public function isValidIP(string $ip, string $which = null): bool;
// CORRECT USAGE
./system/HTTP/RequestInterface.php -> public function isValidIP(string $ip, string $which = ''): bool;
It is worth noting that I think it is advisable to also change the following to blank strings instead of NULL
// INVALID STRING NULL
./system/HTTP/Request.php -> public function isValidIP(string $ip = null, string $which = null): bool
// VALID ACCORDING TO PHP Manual
./system/HTTP/Request.php -> public function isValidIP(string $ip = '', string $which = ''): bool
// ERRORS THROWN DUE TO PHP MANUAL expecting strings and NULL is not a string
https://www.php.net/manual/en/function.filter-var.php
CodeIgniter 4 version
https://github.com/codeigniter4/CodeIgniter4.git
Version - 2020-09-05 - fe016d9
Expected behavior, and steps to reproduce if appropriate
Fatal error: Declaration of CodeIgniter\HTTP\Request::isValidIP(string $ip = '', string $which = ''): bool must be compatible with CodeIgniter\HTTP\RequestInterface::isValidIP(string $ip, ?string $which = NULL): bool in /var/www/ci4-strict.tk/system/HTTP/Request.php on line 240
Context
The text was updated successfully, but these errors were encountered: