Home  >  Article  >  Backend Development  >  Problems with attributes in php object-oriented

Problems with attributes in php object-oriented

WBOY
WBOYOriginal
2016-12-01 00:25:51939browse

class play{

<code>private $message = null;
public function __construct(){

}
public function callback(event $event){
    $this->message = $event->click();
    ...
}</code>

}

Please tell me why you need to add event before $event in public function callback(event $event)? What does the event here do?

Thank you

Reply content:

class play{

<code>private $message = null;
public function __construct(){

}
public function callback(event $event){
    $this->message = $event->click();
    ...
}</code>

}

Please tell me why you need to add event before $event in public function callback(event $event)? What does the event here do?

Thank you

Type declaration: The formal parameter $event must be an instance of (class/interface) event or an instance of a subclass of event (or a class that implements the event interface)

Thank you, that is the parameter type restriction of PHP function. That is, when you call $play->callback($event), if $event is not of type event, an error will be reported. The following picture is a table of the types that PHPfunction parameters can be set.
Problems with attributes in php object-oriented

Strictly limit input types.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn