View Issue Details

IDProjectCategoryView StatusLast Update
0006354OXID eShop (all versions)4.07. Source code, Testpublic2016-03-22 10:20
Reportertimwetter 
PrioritylowSeverityfeatureReproducibilityalways
Status acknowledgedResolutionopen 
Product Version4.9.7 / 5.2.7 
Target VersionFixed in Version 
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
MySQL 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

View 2 revisions

If there is no return null is returned:

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