1 | <?php |
||
25 | class GetGameScore extends TelegramMethods |
||
26 | { |
||
27 | /** |
||
28 | * Target user id |
||
29 | * @var int |
||
30 | */ |
||
31 | public $user_id = 0; |
||
32 | |||
33 | /** |
||
34 | * Required if inline_message_id is not specified. Unique identifier for the target chat |
||
35 | * @var int |
||
36 | */ |
||
37 | public $chat_id; |
||
38 | |||
39 | /** |
||
40 | * Required if inline_message_id is not specified. Identifier of the sent message |
||
41 | * @var int |
||
42 | */ |
||
43 | public $message_id; |
||
44 | |||
45 | /** |
||
46 | * Required if chat_id and message_id are not specified. Identifier of the inline message |
||
47 | * @var string |
||
48 | */ |
||
49 | public $inline_message_id; |
||
50 | |||
51 | public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes |
||
55 | |||
56 | public function getMandatoryFields(): array |
||
62 | } |
||
63 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.