View Issue Details

IDProjectCategoryView StatusLast Update
0006354OXID eShop (all versions)4.07. Source code, Testpublic2022-01-28 17:02
Reportertimwetter Assigned To 
PrioritylowSeverityfeatureReproducibilityalways
Status closedResolutionno change required 
Product Version4.9.7 / 5.2.7 
Summary0006354: oxarticles::getCustomerAlsoBoughtThisProducts missing return
Descriptionoxarticles::getCustomerAlsoBoughtThisProducts:0001056:0001288

in case there is no also bought product the function will nothing return
- there is no explicit 'return null'
- there is no explicit 'return array()'
- there is no explicit 'return false'

please add one of these option to point out how to handle this case of 'empty reply'

THX!
TagsNo tags attached.
ThemeNot defined
BrowserNot defined
PHP VersionNot defined
Database VersionNot defined

Activities

timwetter

2016-03-21 21:12

reporter   ~0011502

@moment this will work without warning&error:

$aProducts = $oArticle->getCustomerAlsoBoughtThisProducts();
if (is_array($aProducts) && count($aProducts) > 0) {
    foreach ($aProducts AS $sKeyArt => $oAlsoArt) {
        //do bla
    }
}

@moment this will throw a warning, if empty return (null):
foreach ($oArticle->getCustomerAlsoBoughtThisProducts() AS $sKeyArt => $oAlsoArt) {
    //do bla
}

QA

2016-03-22 10:19

administrator   ~0011503

However, regardless of the return value, you have to check before using the variable in your foreach loop to NUll, otherwise a warning is thrown.

hendrikfreytag

2016-03-22 10:20

reporter   ~0011504

Last edited: 2016-03-22 10:21

If there is no return null is returned:

http://php.net/manual/en/functions.returning-values.php

SvenBrunk

2022-01-28 14:38

administrator   ~0013544

This is indeed pretty clear. In recent versions a return doc annotation was also added:

@return \OxidEsales\Eshop\Application\Model\ArticleList|null

Nonetheless this is not nice and will probably be subject of a future refactor. But that applies to many return values and is not worth an open ticket in the bugtracker