Welcome Guest, Not a member yet? Register   Sign In
source code says Request::getMethod() is deprecated, what to use?
#1

(This post was last modified: 02-25-2021, 06:04 PM by sneakyimp.)

The source code says Request::getMethod() is deprecated. What should we use instead?
PHP Code:
    /**
     * Get the request method.
     *
     * @param boolean $upper Whether to return in upper or lower case.
     *
     * @return string
     *
     * @deprecated The $upper functionality will be removed and this will revert to its PSR-7 equivalent
     */
    
public function getMethod(bool $upper false): string
    
{
        return (
$upper) ? strtoupper($this->method) : strtolower($this->method);
    } 
Reply
#2

The method is not deprecated, the optional [$upper] parameter is deprecated. In the future the request method name will only be returned in lower case. You may review the documentation here: https://codeigniter.com/user_guide/incom...#getMethod.
Reply
#3

(02-25-2021, 06:01 PM)mlurie Wrote: The method is not deprecated, the optional [$upper] parameter is deprecated. 
Perhaps someone needs to change the comments and remove that @deprecated bit then. In my IDE, this results in the method being displayed in strikethrough text:
Quote:@deprecated The $upper functionality will be removed and this will revert to its PSR-7 equivalent
Reply
#4

Having the same issue:
[Image: hQA8cZI.png]
Reply
#5

The point of the deprecation is to make sure developers are aware of the change coming in the next major release. I’m sorry for the visual issue with your IDE but it has accomplished that goal very nicely.
Reply
#6

use this $method = $_SERVER['REQUEST_METHOD'];
Enlightenment  Is  Freedom
Reply
#7

(This post was last modified: 07-19-2021, 12:45 AM by CCAldo.)

But if you're not using a paramater you still got this error.

Also it seems that some users would be triggered to uses a non-CodeIgniter function instead.
And that would not be the way to handle this case.

Made some adjustments:

PHP Code:
/**
 * Get the request method.
 *
 * @param boolean $upper Whether to return in upper or lower case.
 *
 * @return string
 *
 * The $upper functionality will be removed and this will revert to its PSR-7 equivalent
 *
 * @codeCoverageIgnore
 */
 
public function getMethod(bool $upper false): string
 
{
    if (count(func_get_args()) > 0) {
 
        $warn 'The $upper functionality will be removed and this will revert to its PSR-7 equivalent';
 
        trigger_error($warnE_USER_DEPRECATED);
 
    }
 
    return ($upper) ? strtoupper($this->method) : strtolower($this->method);
 } 


And this trows this when using the $upper-param (in development environments) 
[Image: nkrQxHw.png]

Seems a better way?
Reply
#8

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?
Reply
#9

Its not a huge issue.
Its just triggers the user to chose an alternative function.
The issue is that the error message isn't always clear. 

PhpStorm shows a strikethrough with the notice: Method 'getMethod' is deprecated.
Visual Code has a line under it, with notice: 'getMethod' is depricated.
https://imgur.com/a/4PHcoKk

It's possible to remove all deprecated notices with some settings:
(in Visual Code)
Code:
{
  "editor.showDeprecated": false,
  // "editor.suggest.showDeprecated": false,
  "intelephense.diagnostics.deprecated": false,
}
But that would remove every deprecated notice.


Only found this:
https://stackoverflow.com/questions/2700...ers-in-php
Reply
#10

if ($this->request->getMethod() == 'post') { }
instead we can use
if ($this->request->getPost()) { }
Hope it helps. (CI4 solution)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB