Skip to content
Advertisement

class does not have a method ‘urldecode’

In PHP how can I use the urldecode() inside a class. I have the following class

class exam
{
  function __constract()
  {
    $this->get = $_GET;
    //decode the url
    array_walk_recursive($this->get, array($this, 'urldecode'));
  }
}

because it showing the error

Warning: array_walk_recursive() expects parameter 2 to be a valid callback, class ‘exam’ does not have a method ‘urldecode’ on line 7

Advertisement

Answer

You are passing the current object $this and the method name urldecode so it’s looking for $this->urldecode(). Just pass in the name of the built-in function:

array_walk_recursive($this->get, 'urldecode');

However $_GET variables are already decoded. From urldecode():

Warning The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement