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

Problems with attributes in php object-oriented

WBOY
Release: 2023-03-01 18:48:01
Original
1000 people have browsed it

class play{

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

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

}

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>
Copy after login
Copy after login

}

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.

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template