TemKa_SD Posted February 13, 2019 Share Posted February 13, 2019 Здравствуйте. Восстанавливаю приложение, подзабил на разработку, а тут вышла 4.4. Ошибка: Whoops\Exception\ErrorException: Undefined index: ActiveGamesWidgetType (8) Функции в виджете: public function configuration( &$form=null ) { if ( $form === null ) { $form = new \IPS\Helpers\Form; } $form->add( new \IPS\Helpers\Form\Radio( 'ActiveGamesWidgetType', isset( $this->configuration['ActiveGamesWidgetType'] ) ? $this->configuration['ActiveGamesWidgetType'] : '', TRUE, array( 'options' => array( -1 => 'Лобби && Игры', 0 => 'Игры', 1 => 'Лобби', ) ) ) ); return $form; } public function render() { $games = \IPS\wc3\ActiveGames\ActiveGames::getGamelist( $this->configuration['ActiveGamesWidgetType']); return $this->output( $games } Я так понимаю, нужно ISSET добавить, но он добавлен, что не так? Link to comment Share on other sites More sharing options...
siv1987 Posted February 14, 2019 Share Posted February 14, 2019 Все верно, требуется isset в указанной строке Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 15, 2019 Author Share Posted February 15, 2019 Что не так? Cannot use isset() on the result of an expression (you can use "null !== expression" instead) isset( implode(",", $this->configuration['ActiveGamesWidgetBots']) ) ? implode(",", $this->configuration['ActiveGamesWidgetBots']) : '*', Link to comment Share on other sites More sharing options...
siv1987 Posted February 15, 2019 Share Posted February 15, 2019 Нельзя использовать выражение в isset. Аргумент она принимает только переменную. Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 16, 2019 Author Share Posted February 16, 2019 Блин, в 3.6 не было ошибок вообще. if ( count( $ids ) ) { foreach( $ids as $id ) { $botIds = array_filter( $ids, 'intval' ); } if ( count( $botIds ) ) { $where[] = array( \IPS\Db::i()->in( 'botid', array_filter( $botIds ) ) ); } } Whoops\Exception\ErrorException: You have used a function (count) that should be called from the root namespace for performance reasons Link to comment Share on other sites More sharing options...
siv1987 Posted February 16, 2019 Share Posted February 16, 2019 Нужно указать что count из глобальной области, а не из какого нибудь пространство имен (добавить обратный слеш перед функцией) \count( $var ) Link to comment Share on other sites More sharing options...
newbie Posted February 16, 2019 Share Posted February 16, 2019 Там еще несколько ф-й IPS проверяют в 4.4 при включенном режиме разработчика. Если не хотите ставить слеш, то можно добавить в constants.php define( 'IN_DEV_STRICT_MODE', FALSE );Либо использовать какой-нибудь автоматический инструмент, который добавит слеши по всему коду. 1 Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 16, 2019 Author Share Posted February 16, 2019 Спасибо, лучше ручками слеш поставлю, если так нужно делать ) Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 16, 2019 Author Share Posted February 16, 2019 Что не так? foreach( static::getUsers($g->getUsernames()) as $realm ) { isset( $realms ) ? $realms[ $realm['realm'] ]++ : ''; } Link to comment Share on other sites More sharing options...
newbie Posted February 16, 2019 Share Posted February 16, 2019 Что не так?А что не так? $realms = array(); foreach( static::getUsers($g->getUsernames()) as $realm ) { isset( $realms[ $realm['realm'] ] ) ? $realms[ $realm['realm'] ]++ : $realms[ $realm['realm'] ] = 1; } Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 16, 2019 Author Share Posted February 16, 2019 Переменную в виде массива во всех случаях объявлять нужно? Ну всмысле там, где она используется в виде массива. isset( $realms[ $realm['realm'] ] ) ? $realms[ $realm['realm'] ]++ : $realms[ $realm['realm'] ] = 1; Это понятно, если существует $realms[ $realm['realm'] ] то выбрать $realms[ $realm['realm'] ]++ иначе $realms[ $realm['realm'] ] = 1. Зачем тут 1? И не правильно выбрались данные: http://prntscr.com/mlvepl Убрал: $realms = array(); Link to comment Share on other sites More sharing options...
newbie Posted February 16, 2019 Share Posted February 16, 2019 Переменную в виде массива во всех случаях объявлять нужно? Ну всмысле там, где она используется в виде массива.Не только массив. Зачем тут 1?А что должно быть? Если еще нет $realms[ $realm['realm'] ], то создаем и присваиваем 1. Иначе количество для каждого индекса будет на единицу меньшеforeach (array(1,2,3,4,5,1,5,5) as $i) { isset($realms[$i]) ? $realms[$i]++ : $realms[$i] = 1; } две единицыодна двойкаодна тройкаодна четверкатри пятерки На выходе [1] => 2 [2] => 1 [3] => 1 [4] => 1 [5] => 3 И не правильно выбрались данные: http://prntscr.com/mlveplВам виднее. У вас там вообще цикл в цикле. Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 16, 2019 Author Share Posted February 16, 2019 Не работает оно. Если в игре 0 игроков, т.е срабатывает именно $realms[ $realm['realm'] ] = 1 то ошибка Invalid argument supplied for foreach(). Хотя, это наверно в count надо оборачивать? Если count есть, то выводить данные. Link to comment Share on other sites More sharing options...
TemKa_SD Posted February 16, 2019 Author Share Posted February 16, 2019 Я правильно сделал? http://prntscr.com/mlwkdv {{if $stats['players']}} Link to comment Share on other sites More sharing options...
siv1987 Posted February 16, 2019 Share Posted February 16, 2019 В php 7 не знаю какой ревизии есть такая штука как ?? (объединения с null) $realms[ $realm['realm'] ] = $realms[ $realm['realm'] ] ?? 0; $realms[ $realm['realm'] ]++; Или по старинке $realms[ $realm['realm'] ] = isset( $realms[ $realm['realm'] ] ) ? $realms[ $realm['realm'] ] + 1 : 1; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now