mambax7 /
wflinks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * Module: WF-Links |
||
| 4 | * Version: v1.0.3 |
||
| 5 | * Release Date: 21 June 2005 |
||
| 6 | * Developer: John N |
||
| 7 | * Team: WF-Projects |
||
| 8 | * Licence: GNU |
||
| 9 | */ |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @param $category |
||
| 13 | * @param $item_id |
||
| 14 | * |
||
| 15 | * @return null |
||
| 16 | */ |
||
| 17 | function wflinks_notify_iteminfo($category, $item_id) |
||
| 18 | { |
||
| 19 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 20 | global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
||
| 21 | |||
| 22 | if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != $moduleDirName) { |
||
| 23 | /** @var XoopsModuleHandler $moduleHandler */ |
||
| 24 | $moduleHandler = xoops_getHandler('module'); |
||
| 25 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
| 26 | $configHandler = xoops_getHandler('config'); |
||
| 27 | $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 28 | } else { |
||
| 29 | $module = $xoopsModule; |
||
| 30 | $config = $xoopsModuleConfig; |
||
| 31 | } |
||
| 32 | |||
| 33 | if ('global' === $category) { |
||
| 34 | $item['name'] = ''; |
||
|
0 ignored issues
–
show
|
|||
| 35 | $item['url'] = ''; |
||
| 36 | |||
| 37 | return $item; |
||
| 38 | } |
||
| 39 | |||
| 40 | global $xoopsDB; |
||
| 41 | if ('category' === $category) { |
||
| 42 | // Assume we have a valid category id |
||
| 43 | $sql = 'SELECT title FROM ' . $xoopsDB->prefix('wflinks_cat') . ' WHERE cid=' . $item_id; |
||
| 44 | if (!$result = $xoopsDB->query($sql)) { |
||
| 45 | return false; |
||
| 46 | } |
||
| 47 | $result_array = $xoopsDB->fetchArray($result); |
||
| 48 | $item['name'] = $result_array['title']; |
||
| 49 | $item['url'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $item_id; |
||
| 50 | |||
| 51 | return $item; |
||
| 52 | } |
||
| 53 | |||
| 54 | if ('link' === $category) { |
||
| 55 | // Assume we have a valid file id |
||
| 56 | $sql = 'SELECT cid,title FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $item_id; |
||
| 57 | if (!$result = $xoopsDB->query($sql)) { |
||
| 58 | return false; |
||
| 59 | } |
||
| 60 | $result_array = $xoopsDB->fetchArray($result); |
||
| 61 | $item['name'] = $result_array['title']; |
||
| 62 | $item['url'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlelink.php?cid=' . $result_array['cid'] . '&lid=' . $item_id; |
||
| 63 | |||
| 64 | return $item; |
||
| 65 | } |
||
| 66 | |||
| 67 | return null; |
||
| 68 | } |
||
| 69 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.