Request $ request in object-oriented PHP

1

I'm doing some exercises in PHP OO and I came across some functions that call a class before the variable. But I did not really understand why.

For example:

public function Exemplo(Request $request, $nome, $sobrenome) {
   // métodos
}

If I call a class to use as a parameter, why not use a comma to stop the variable class?

It should be something simple, but this is causing confusion here. Thank you for letting me know.

hug.

    
asked by anonymous 31.08.2018 / 01:58

1 answer

0

There is no typing in php at first ... But in this case, the variable $request has a type yes, type Request .

Now, imagine with us, you make a code, where you assign a int to the variable $request by mistake ... You would lose all $ request information: data, cookies, tokens ...

"Typing" the variable $request you do not make unnecessary assignments in it, and accidental loss of variables.

PS: You are not using a class as a parameter, you are setting $request to type Request , just like typed languages you do with other variables, such as int numero; , double numero , String texto ...

I hope I have helped!

    
31.08.2018 / 15:28