View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0006354 | OXID eShop (all versions) | 4.07. Source code, Test | public | 2016-03-21 20:53 | 2022-01-28 17:02 |
Reporter | timwetter | Assigned To | |||
Priority | low | Severity | feature | Reproducibility | always |
Status | closed | Resolution | no change required | ||
Product Version | 4.9.7 / 5.2.7 | ||||
Summary | 0006354: oxarticles::getCustomerAlsoBoughtThisProducts missing return | ||||
Description | oxarticles::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! | ||||
Tags | No tags attached. | ||||
Theme | Not defined | ||||
Browser | Not defined | ||||
PHP Version | Not defined | ||||
Database Version | Not defined | ||||
|
@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 } |
|
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. |
|
If there is no return null is returned: http://php.net/manual/en/functions.returning-values.php |
|
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 |