#25515 [NEW]: HTTP_Session fails with strict error_handling

From: Date: Fri, 12 Sep 2003 14:12:57 +0000
Subject: #25515 [NEW]: HTTP_Session fails with strict error_handling
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-21431@lists.php.net to get a copy of this message
From: info at rhalff dot com Operating system: linux PHP version: Irrelevant PHP Bug Type: PEAR related Bug description: HTTP_Session fails with strict error_handling Description: ------------ When using a custom php error handler, HTTP_Session will fail because of an Undefined index in /usr/lib/php/HTTP/Session.php at line 545 A simple fix for this would be, to check if it is empty: /** * Sets new local name * * @static * @access public * @param string New local name * @return string Previous local name */ function localName($name = null) { if(!isset($GLOBALS['__HTTP_Session_Localname'])) { $GLOBALS['__HTTP_Session_Localname'] = null; } $return = $GLOBALS['__HTTP_Session_Localname']; if (isset($name)) { $GLOBALS['__HTTP_Session_Localname'] = $name; } return $return; } After this fix is applied HTTP_Session:start will be succesfull, but HTTP_Session::setLocal will fail with an undefined index too. A fix for this method would be: function setLocal($name, $value) { $local = md5(HTTP_Session::localName()); if (!isset($_SESSION[$local])) { $_SESSION[$local] = array(); } if (!isset($_SESSION[$local][$name])) { $_SESSION[$local][$name] = null; } $return = $_SESSION[$local][$name]; if (null === $value) { unset($_SESSION[$local][$name]); } else { $_SESSION[$local][$name] = $value; } return $return; } As with the last method HTTP:Session:set: function set($name, $value) { if(!isset($_SESSION[$name])) { $_SESSION[$name] = null; } $return = $_SESSION[$name]; if (null === $value) { unset($_SESSION[$name]); } else { $_SESSION[$name] = $value; } return $return; } Reproduce code: --------------- require_once ("PEAR.php"); require_once ("HTTP/Session.php"); function php_error_handler($errno, $errstr, $errfile, $errline) { echo "$errstr in $errfile at line $errline"; exit(); } set_error_handler('php_error_handler'); HTTP_Session::start('SessionID', uniqid('MyID')); HTTP_Session::setLocal('name','value'); HTTP_Session::setLocal('name2','value'); echo "finished"; Expected result: ---------------- finished Actual result: -------------- Undefined index in /usr/lib/php/HTTP/Session.php at linenr -- Edit bug report at http://bugs.php.net/?id=25515&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25515&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25515&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25515&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25515&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25515&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25515&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25515&r=support Expected behavior: http://bugs.php.net/fix.php?id=25515&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25515&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25515&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25515&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25515&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25515&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25515&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25515&r=gnused

« previous php.pear.dev (#21431) next »