1 | <?php |
||
24 | class SetGameScore extends TelegramMethods |
||
25 | { |
||
26 | /** |
||
27 | * User identifier |
||
28 | * @var int |
||
29 | */ |
||
30 | public $user_id = 0; |
||
31 | |||
32 | /** |
||
33 | * New score, must be non-negative |
||
34 | * @var int |
||
35 | */ |
||
36 | public $score = 0; |
||
37 | |||
38 | /** |
||
39 | * Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters |
||
40 | * @var boolean |
||
41 | */ |
||
42 | public $force = false; |
||
43 | |||
44 | /** |
||
45 | * Pass True, if the game message should not be automatically edited to include the current scoreboard |
||
46 | * @var boolean |
||
47 | */ |
||
48 | public $disable_edit_message = false; |
||
49 | |||
50 | /** |
||
51 | * Required if inline_message_id is not specified. Unique identifier for the target chat |
||
52 | * @var int |
||
53 | */ |
||
54 | public $chat_id; |
||
55 | |||
56 | /** |
||
57 | * Required if inline_message_id is not specified. Identifier of the sent message |
||
58 | * @var int |
||
59 | */ |
||
60 | public $message_id; |
||
61 | |||
62 | /** |
||
63 | * Required if chat_id and message_id are not specified. Identifier of the inline message |
||
64 | * @var string |
||
65 | */ |
||
66 | public $inline_message_id; |
||
67 | |||
68 | public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes |
||
80 | |||
81 | public function getMandatoryFields(): array |
||
88 | } |
||
89 |
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.