Skip to content

Commit

Permalink
Fix array access to nullable property
Browse files Browse the repository at this point in the history
Trying to access array offset on value of type null (protected/models/User.php:318)

Stack trace:
#0 yii/framework/base/CComponent.php(111): User->getUpicUrl()
#1 yii/framework/db/ar/CActiveRecord.php(145): User->__get()
basavind#2 protected/views/users/profile_head.php(15): User->__get()
basavind#3 yii/framework/web/CBaseController.php(126): require()
basavind#4 yii/framework/web/CBaseController.php(95): UsersController->renderInternal()
basavind#5 yii/framework/web/CController.php(872): UsersController->renderFile()
basavind#6 protected/views/users/books.php(15): UsersController->renderPartial()
uisky#7 yii/framework/web/CBaseController.php(126): require()
uisky#8 yii/framework/web/CBaseController.php(95): UsersController->renderInternal()
uisky#9 yii/framework/web/CController.php(872): UsersController->renderFile()
uisky#10 yii/framework/web/CController.php(785): UsersController->renderPartial()
uisky#11 protected/controllers/UsersController.php(186): UsersController->render()
uisky#12 unknown(0): UsersController->actionBooks()
uisky#13 yii/framework/web/actions/CAction.php(115): ReflectionMethod->invokeArgs()
uisky#14 yii/framework/web/actions/CInlineAction.php(47): CInlineAction->runWithParamsInternal()
uisky#15 yii/framework/web/CController.php(308): CInlineAction->runWithParams()
uisky#16 yii/framework/web/filters/CFilterChain.php(134): UsersController->runAction()
#17 yii/framework/web/CController.php(291): CFilterChain->run()
#18 yii/framework/web/CController.php(265): UsersController->runActionWithFilters()
#19 yii/framework/web/CWebApplication.php(282): UsersController->run()
#20 yii/framework/web/CWebApplication.php(141): CWebApplication->runController()
#21 yii/framework/base/CApplication.php(185): CWebApplication->processRequest()
#22 www/index.php(15): CWebApplication->run()
  • Loading branch information
bmanolov committed Oct 8, 2023
1 parent d0d6983 commit 7becd99
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions protected/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,27 @@ public function getUpicDir() {
}

public function getUpicPath() {
if($this->upic[0] == 0) return "";
if($this->hasDefaultPicture()) return "";
return $this->upicDir . "/{$this->upicName}.jpg";
}

public function getUpicPathBig() {
if($this->upic[0] == 0) return "";
if($this->hasDefaultPicture()) return "";
return $this->upicDir . "/{$this->upicName}_big.jpg";
}

public function getUpicUrl() {
if($this->upic[0] == 0) return "/i/avatar_placeholder.png";
if($this->hasDefaultPicture()) return "/i/avatar_placeholder.png";
return "/i/upic/" . floor($this->id / 1000) . "/" . $this->upicName . ".jpg";
}

public function getUpicUrlBig() {
if($this->upic[0] == 0) return "";
if($this->hasDefaultPicture()) return "";
return "/i/upic/" . floor($this->id / 1000) . "/" . $this->upicName . "_big.jpg";
}

public function upicUnlink() {
if($this->upic[0] == 0) return false;
if($this->hasDefaultPicture()) return false;
@unlink($this->upicPath);
@unlink($this->upicPathBig);
$this->upic = array(0, 0, 0);
Expand Down Expand Up @@ -406,4 +406,8 @@ public function Notify($typ, $param1, $param2 = null, $param3 = null) {

return true;
}

protected function hasDefaultPicture(): bool {
return $this->upic === null || $this->upic[0] == 0;
}
}

0 comments on commit 7becd99

Please sign in to comment.