Andy
Andy

Reputation: 5395

Class name before variable in PHP function argument

In lots of PHP scripts I see things such as this:

public function __construct(Container $ci) {

}

I understand what a constructor does and how to pass a variable. However I'm not sure what Container means in this example? Is this the equivalent of $ci = new Container; ?

Upvotes: 3

Views: 1401

Answers (2)

Uri
Uri

Reputation: 131

For those who are looking for "Type Hinting" and using the broken links above, in PHP this is now known as Type Declaration.

https://www.php.net/manual/en/language.types.declarations.php

Upvotes: 0

Rax Weber
Rax Weber

Reputation: 3780

No, it is just type hinting the method's $ci parameter, meaning that you should pass an argument declared as an instance of Container like so:

$cont = new Container();

$obj = new YourClass($cont);

Upvotes: 8

Related Questions