0

when I see parameters in a function in the form of a class name, what does it mean? how can you google it? it is clear that if there is an array in front of a variable, it must be a variable of the array type, but if the class is in front of the variable, what does this mean?

public function scopeFilter(Builder $builder, array $filter)
     { /**/ }

I tried to google but couldn't find it

1
  • Builder is object of class, array is array if there is no indicated type - then you need to read the function code and deduce what it can be. Commented Dec 31, 2022 at 14:48

1 Answer 1

1

It is known as Type hinting and has been part of the PHP core since version 5.

As per the documentation:

They ensure that the value is of the specified type at call time, otherwise a TypeError is thrown.

So using your example, if you tried to call your scopeFilter function and provide it with arguments that were not a Builder and an array, you'd get a runtime error.

There are plenty of articles available should you want to read more about type hinting.

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.