1
I’m doing some PHP OO exercises and came across some functions that call a class before the variable. But I didn’t really understand why.
For example:
public function Exemplo(Request $request, $nome, $sobrenome) {
// métodos
}
if I call a class to use as parameter because comma is not used to stop the class of the variable ?
It must be something simple, but it’s causing confusion here. I’d appreciate it if you could enlighten me
hug.
It is not parameter, there is being warned that $request is "type" Request (can not for an integer, a string or something, has to be an object of type Request)
– Bacco
I am still confused. Then the $request variable will be treated as a Request ? class heretic inheriting all its attributes and methods ?
– 1001Songs Clips
This means if the variable that the Laravel should enter must be a Request object. Ex:
$request = new Request(); $controller = new Controller(); $controller->Exemplo($request);
. Like Bacco said, it can’t be$controller->Exemplo("string");
or$controller->Exemplo(123456)
.– Valdeir Psr
https://secure.php.net/manual/en/functions.arguments.php#example-154
– Valdeir Psr
Hmm. Let’s assume I create a class like this:
class Soma { public function Somar(){ return 25 + 25; } }
--- So I want to call this function on another leaf doing so:public function SomarTotal ( Somar $somar ) {}
Then when I call the function I must inform an object of type Somar, right ? like this:$a = new SomarTotal; $a->Somar();
Is that it ??? Vish ta fuck assimilate it– 1001Songs Clips
It’s not that complex. The name of it is
Types Hinting
. http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration– Valdeir Psr
Oops, good brother. The name is already worth a lot. I will study in depth here.. vlw
– 1001Songs Clips