XoopsModules25x /
xoopstube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | /* |
||
| 3 | You may not change or alter any portion of this comment or credits |
||
| 4 | of supporting developers from this source code or any supporting source code |
||
| 5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | /** |
||
| 12 | * XoopstubeSession class |
||
| 13 | * |
||
| 14 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||
| 15 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||
| 16 | * @package Xoopstube |
||
| 17 | * @since 1.0 |
||
| 18 | * @author trabis <[email protected]> |
||
| 19 | * @author Harry Fuecks (PHP Anthology Volume II) |
||
| 20 | * @version $Id: session.php 10283 2012-11-28 13:39:36Z trabis $ |
||
| 21 | */ |
||
| 22 | // defined('XOOPS_ROOT_PATH') || die('XOOPS Root Path not defined'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
70% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 23 | |||
| 24 | include_once dirname(__DIR__) . '/include/common.php'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Class XoopstubeSession |
||
| 28 | */ |
||
| 29 | class XoopstubeSession |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * Session constructor<br /> |
||
| 33 | * Starts the session with session_start() |
||
| 34 | * <strong>Note:</strong> that if the session has already started, |
||
| 35 | * session_start() does nothing |
||
| 36 | */ |
||
| 37 | protected function __construct() |
||
| 38 | { |
||
| 39 | @session_start(); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Sets a session variable |
||
| 44 | * |
||
| 45 | * @param string $name name of variable |
||
| 46 | * @param mixed $value value of variable |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | * @access public |
||
| 50 | */ |
||
| 51 | public function set($name, $value) |
||
| 52 | { |
||
| 53 | $_SESSION[$name] = $value; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Fetches a session variable |
||
| 58 | * |
||
| 59 | * @param string $name name of variable |
||
| 60 | * |
||
| 61 | * @return mixed value of session variable |
||
| 62 | * @access public |
||
| 63 | */ |
||
| 64 | public function get($name) |
||
| 65 | { |
||
| 66 | if (isset($_SESSION[$name])) { |
||
| 67 | return $_SESSION[$name]; |
||
| 68 | } else { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Deletes a session variable |
||
| 75 | * |
||
| 76 | * @param string $name name of variable |
||
| 77 | * |
||
| 78 | * @return void |
||
| 79 | * @access public |
||
| 80 | */ |
||
| 81 | public function del($name) |
||
| 82 | { |
||
| 83 | unset($_SESSION[$name]); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Destroys the whole session |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | * @access public |
||
| 91 | */ |
||
| 92 | public function destroy() |
||
| 93 | { |
||
| 94 | $_SESSION = array(); |
||
| 95 | session_destroy(); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return XoopstubeSession |
||
| 100 | */ |
||
| 101 | public static function &getInstance() |
||
| 102 | { |
||
| 103 | static $_sess; |
||
| 104 | if (!isset($_sess)) { |
||
| 105 | $_sess = new XoopstubeSession(); |
||
| 106 | } |
||
| 107 | |||
| 108 | return $_sess; |
||
| 109 | } |
||
| 110 | } |
||
| 111 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.