0

i trie to figure out what the use of the "text" is before te propery/variable in the contructor. What is the use of "TableGatewayInterface" in the constructor in the example below?

use Laminas\Db\TableGateway\TableGatewayInterface;

private function __construct(TableGatewayInterface $tableGateway)
{
     $this->tableGateway = $tableGateway;
}
4
  • @MarkusZeller i do not understand :-( Commented Nov 25, 2023 at 15:49
  • 2
    wiki.php.net/rfc/constructor_promotion Commented Nov 25, 2023 at 15:49
  • 4
    If you're just asking what TableGatewayInterface means - it's a type-hint. It means the function can't be called with any other type of variable, or a TypeError will be raised. Commented Nov 25, 2023 at 15:50
  • 2
    Ah, my bad. I thought you meant what value the property has before defined. But read the link I sent, anyways, because it explains your question, too with examples. Commented Nov 25, 2023 at 15:53

1 Answer 1

1

It states that $tableGateway property must come from TableGatewayInterface, must be declared in that aliased struct. It means that You cannot simply make an instance with such constructor, with parameter of any value of Your choice, but with named parameter strictly from TableGatewayInterface.

Here is nice insight for You: List of Types Supported By PHP

Research PHP named parameters and return type declarations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.