devmyb devmyb - 1 month ago 13
PHP Question

Getting an error for double and boolean even boolean given

As prior to one of the question available on SO i.e Really PHP? "Argument 1 passed to my_function() must be an instance of string, string given". I've conducted test for this but I got strange error for

double
and
boolean
gives me an error


Uncaught TypeError: Argument 5 passed to A::getData() must be an instance of double, float given,
Uncaught TypeError: Argument 6 passed to A::getData() must be an instance of boolean, boolean given,


class A{
/**
* [getData description]
* @param array $data [description]
* @param string $a [description]
* @param int $b [description]
* @param boolean $c [description]
* @param float $d [description]
* @return [type] [description]
*/
public function getData(array $data, string $a, int $b, float $f, double $d, boolean $c)
{}
}

$a = new A();
$a->getData(["as"],"assasa",12345, 64.153454, 65.41, true);


You can check this over here

Answer

There is no double type hinting. And boolean should be changed to bool. Your PHPDoc controls didn't match te parameters too

     /**
     * [getData description]
     * @param  array   $data [description]
     * @param  string  $a    [description]
     * @param  int     $b    [description]
     * @param  double   $f    [description]
     * @param  float $d     [description]
     * @param  bool $c    [description]
     * @return [type]        [description]
     */

     public function getData(array $data, string $a, int $b, $f, float $d, bool $c)
     {

     } 



$a->getData(["as"],"assasa",12345,65.41,64.153454 , true);