walkor / webman

Probably the fastest PHP web framework in the world.
https://webman.workerman.net/
MIT License
2.21k stars 216 forks source link

parse_str issue in php 8.1 - error on empty $request->get('variable') #255

Open vilords opened 2 years ago

vilords commented 2 years ago

ErrorException: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/.../vendor/workerman/workerman/Protocols/Http/Request.php:446 Stack trace:

0 [internal function]: {closure}(8192, 'parse_str(): Pa...', '/var/www/...', 446)

1 /var/www/.../vendor/workerman/workerman/Protocols/Http/Request.php(446): parse_str(NULL, Array)

2 /var/www/.../vendor/workerman/workerman/Protocols/Http/Request.php(111): Workerman\Protocols\Http\Request->parseGet()

3 /var/www/.../app/controller/list_fonts.php(24): Workerman\Protocols\Http\Request->get('f')

4 /var/www/.../vendor/workerman/webman-framework/src/App.php(253): app\controller\list_fonts->category(Object(support\Request), 'miscellaneous-f...')

5 /var/www/.../vendor/workerman/webman-framework/src/App.php(146): Webman\App::Webman{closure}(Object(support\Request))

6 /var/www/.../vendor/workerman/workerman/Connection/TcpConnection.php(638): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))

7 [internal function]: Workerman\Connection\TcpConnection->baseRead(Resource id #236, 2, Resource id #236)

8 /var/www/.../vendor/workerman/workerman/Events/Event.php(193): EventBase->loop()

9 /var/www/.../vendor/workerman/workerman/Worker.php(2418): Workerman\Events\Event->loop()

10 /var/www/.../vendor/workerman/workerman/Worker.php(1542): Workerman\Worker->run()

11 /var/www/.../vendor/workerman/workerman/Worker.php(1373): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker))

12 /var/www/.../vendor/workerman/workerman/Worker.php(1347): Workerman\Worker::forkWorkersForLinux()

13 /var/www/.../vendor/workerman/workerman/Worker.php(542): Workerman\Worker::forkWorkers()

14 /var/www/.../start.php(156): Workerman\Worker::runAll()

15 {main}

walkor commented 2 years ago

Please upgrade workerman/workerman to v4.0.23 or greater. upgrade workerman/webman-framework to v1.0.21 or greater. upgrade workerman/webman tp v1.1.3 or grater.

vilords commented 2 years ago

Hi,

Still have the same issue, even after I upgraded to the latest libs (workerman, webman-framework, and even webman itself).

Anyway, seems PHP 8.1 throws errors when using NULL values in parse_str.

After slight fix in wokerman/Protocols/Http/Request.php (parsePost() function) it's working:

if ($query_string === '' || $query_string === NULL) { return; }

Would be great if you could fix it in the main lib.

Thanks!

Keep up the great work.

walkor commented 2 years ago

@vilords Can you tell me which line throws the errors?

vilords commented 2 years ago

If you'll try to grab an empty get variable in a controller:

$my_var = $request->get('query_var');

That's strictly an 8.1 issue, 8.0 doesn't throw errors when NULL variable used in parse_str and similar functions.

On Thu, Dec 2, 2021 at 3:16 PM walkor @.***> wrote:

@vilords https://github.com/vilords Can you tell me which line throws the errors?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/walkor/webman/issues/255#issuecomment-984666779, or unsubscribe https://github.com/notifications/unsubscribe-auth/AINFIN24J3GWTFZ7B6DEWF3UO55S7ANCNFSM5JCMPJ5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

walkor commented 2 years ago

@vilords Fixed in v4.0.24

vilords commented 2 years ago

Thanks!