CodeIgniter Forums
source code says Request::getMethod() is deprecated, what to use? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: source code says Request::getMethod() is deprecated, what to use? (/showthread.php?tid=78685)

Pages: 1 2


RE: source code says Request::getMethod() is deprecated, what to use? - InsiteFX - 07-30-2021

Anyway to hide/suppress deprecated warnings you may do this

error_reporting(E_ALL ^ E_DEPRECATED);


RE: source code says Request::getMethod() is deprecated, what to use? - alphastudiofr - 03-29-2023

+1 on not using @deprecated in the docblock when the function as a whole is not deprecated.

phpDocument defines the tag as meaning the element associated with the docblock is deprecated (in this case the method as a whole, not just one of its functionalities):
https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/deprecated.html#deprecated

IDEs implement the same logic, leading to the method showing as strike through in the code and other various warnings.

For instance in PhpStorm, hovering the method, you do get the detailed comment on the $upper functionality if you read through, but the main message is "Method 'getMethod' is deprecated".

[Image: getmethod.png]

Triggering the wrong warning is never a good strategy. Deprecated warnings are useful when they can lead to a fix. In this case, there is no fix, so you're left with a permanent warning, and the idea that CodeIgniter's code triggers false alarms that you just have to ignore... Never a good thing if awareness is what you want to achieve.


RE: source code says Request::getMethod() is deprecated, what to use? - kenjis - 03-29-2023

@alphastudiofr Thank you for your opinion.
We don't think the current way is the best.
If you have a better way to inform CI4 users that, please send a PR.
https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md


RE: source code says Request::getMethod() is deprecated, what to use? - kenjis - 03-29-2023

I recommend to use the new is() method.
https://codeigniter.com/user_guide/incoming/incomingrequest.html#is


RE: source code says Request::getMethod() is deprecated, what to use? - objecttothis - 12-07-2023

(07-19-2021, 05:02 AM)MGatner Wrote: We are working on a framework-wide implementation for handling use of deprecated features. This would definitely be the kind of approach it would take.

I don’t use an IDE so I obviously don’t have this problem - but how much of an issue is it really? I was under the impression you just got a little flag saying “deprecated” or something.

Anyone have references for best practices or other framework handling did deprecating a parameter while leaving the method/function?

Sorry for the necro, but it seems the way to possibly deprecate the parameter is to overload the function without the parameter, then keep the deprecation notice on this one but not on the overloaded function... nevermind, I just realized that overloading in php is ... a-typical. https://www.php.net/manual/en/language.oop5.overloading.php


RE: source code says Request::getMethod() is deprecated, what to use? - kenjis - 12-07-2023

We will remove the deprecated feature in 4.5.