0

I am reading about design patterns in PHP and I keep seeing the following syntax, for example

abstract class AbstractObserver { abstract function update(AbstractSubject $subject_in); } 

or

class PatternObserver extends AbstractObserver { public function __construct() { } public function update(AbstractSubject $subject) { } } 

(code is part of this example)

where "AbstractSubject" is another abstract class.

I am used to defining methods like methodName($var), not including a class name in there, like methodName(className $var).

So, what actually the class name does in a method ? My best guess is that it passes something like a reference in that class? Can you explain to me what it actually does?

Thanks

1
  • 1
    It's called Type Hinting, and it defines the datatype that the argument must be Commented Sep 18, 2017 at 21:32

1 Answer 1

1

It's called Type Hinting, since php 7 you can use scalar types to type hint parameters. (Some more)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.