From: SourceForge.net <no...@so...> - 2009-11-21 14:01:03
|
Bugs item #2897990, was opened at 2009-11-15 13:34 Message generated for change (Comment added) made by liedekef You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=108956&aid=2897990&group_id=8956 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: User >Group: svn >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Arjen van Bochoven (bochoven) Assigned to: Nobody/Anonymous (nobody) Summary: uninitialized GLOBALS array breaks esp_setlocale() Initial Comment: On line 94 of php.ini.fixed, a call is made to esp_setlocale_ex() which in turn calls esp_setlocale() (both live in espi18n.inc). On line 110, 114 and 115 of espi18n.inc, esp_setlocale() accesses $ESPCONFIG as a global variable, which is not initialized yet. Initialization of $GLOBALS['ESPCONFIG'] happens at the end of php.ini.fixed, so after the part that references esp_setlocale(); As a quick fix I moved the initialization part above the esp_setlocale() calls. As a consequence, all references to the ESPCONFIG array that come after that have to be changed to $GLOBALS['ESPCONFIG'] here's my changed code for php.ini.fixed starting on line 91 till the end of the file: if (isset($GLOBALS)) { $GLOBALS['ESPCONFIG'] = $ESPCONFIG; } else { global $ESPCONFIG; } // Load I18N support require_once($GLOBALS['ESPCONFIG']['include_path'] . '/lib/espi18n' . $GLOBALS['ESPCONFIG']['extension']); if (isset($_REQUEST['lang'])) { esp_setlocale_ex($_REQUEST['lang']); $_SESSION['language']=$_REQUEST['lang']; } elseif (isset($lang)) { esp_setlocale_ex($lang); $_SESSION['language']=$lang; } elseif (isset($_SESSION['language'])) { esp_setlocale_ex($_SESSION['language']); } else { esp_setlocale_ex(); } // default thank you messages $GLOBALS['ESPCONFIG']['thank_head'] = _('Thank You For Completing This Survey.'); $GLOBALS['ESPCONFIG']['thank_body'] = _('Please do not use the back button on your browser to go back.'); if (!file_exists($GLOBALS['ESPCONFIG']['include_path']. '/funcs'. $GLOBALS['ESPCONFIG']['extension'])) { printf('<b>'. _('Unable to find the phpESP %s directory. Please check %s to ensure that all paths are set correctly.') . '</b>', 'include', 'phpESP.ini.php'); exit; } if (!file_exists($GLOBALS['ESPCONFIG']['css_path'])) { printf('<b>'. _('Unable to find the phpESP %s directory. Please check %s to ensure that all paths are set correctly.') . '</b>', 'css', 'phpESP.ini.php'); exit; } require_once($GLOBALS['ESPCONFIG']['include_path'].'/funcs'.$GLOBALS['ESPCONFIG']['extension']); ?> ---------------------------------------------------------------------- >Comment By: Franky Van Liedekerke (liedekef) Date: 2009-11-21 15:01 Message: Agreed, note added in a new readme.txt file in the examples subdir ---------------------------------------------------------------------- Comment By: Arjen van Bochoven (bochoven) Date: 2009-11-21 12:11 Message: Solved: when I declare the following inside the function: global $ESPCONFIG; all is fine, my previous hacking of the config files is unnecessary. Maybe update documentation to state that when the include is done inside a function, you have to declare the $ESPCONFIG array as global. I am including phpESP in a CMS based on CodeIgniter, a MVC framework. In CI, views (templates) don't exist in global scope so setting global $ESPCONFIG; fixes the variable problem. ---------------------------------------------------------------------- Comment By: Arjen van Bochoven (bochoven) Date: 2009-11-21 12:04 Message: Moving the phpESP.first.php to the top of the script does not make a difference, please mind that I am including /public/handler.php inside a function. This is indeed a matter of scope, variables that are declared outside the function are not available within it. In your example, if I replace <?php include("/path/phpESP/public/handler.php"); ?> with <?php function survey(){include("/path/phpESP/public/handler.php");} survey(); ?> I get these messages: Notice: Undefined variable: ESPCONFIG in /path/phpESP/public/handler.php on line 26 Notice: Undefined variable: ESPCONFIG in /path/phpESP/public/handler.php on line 26 Warning: require_once(/funcs) [function.require-once]: failed to open stream: No such file or directory in /path/phpESP/public/handler.php on line 26 ---------------------------------------------------------------------- Comment By: Franky Van Liedekerke (liedekef) Date: 2009-11-18 22:35 Message: Look at the comments in the examples php files: the include of public/phpESP.first.php needs to happen BEFORE any output begins (reason: session initialization etc) Try this: <?php ini_set( 'display_errors', true ); error_reporting(E_ALL); $lang='nl_NL'; $sid=9; include("/home/bochoven/php/phpESP/public/phpESP.first.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>survey</title> </head> <body> <?php include("/home/bochoven/php/phpESP/public/handler.php"); ?> </body> </html> ---------------------------------------------------------------------- Comment By: Franky Van Liedekerke (liedekef) Date: 2009-11-18 22:16 Message: I found this one weird, so I took a deeper look at it. First of all: I don't like the use of global variables, but that put aside, I believe this remark to be wrong: in php, using "global <variablename>", refers to the value of the variable outside the function, see http://php.net/manual/en/language.variables.scope.php (example 2). Using $GLOBALS should be removed as much as possible, but I didn't get around to doing that (yet), but still it doesn't change the fact that it remains the same. What did you see as an error when you claim that "uninitialized GLOBALS array breaks esp_setlocale()"? ---------------------------------------------------------------------- Comment By: Arjen van Bochoven (bochoven) Date: 2009-11-15 20:28 Message: Hmm, further investigation showed that this problem only arises when you don't include the handler.php in global space (eg in a function or a class). I would still want to flag this as a bug. Example code below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>survey</title> </head> <body> <?php ini_set( 'display_errors', true ); error_reporting(E_ALL); function survey() { $lang='nl_NL'; $sid=9; include("/home/bochoven/php/phpESP/public/phpESP.first.php"); include("/home/bochoven/php/phpESP/public/handler.php"); } survey(); ?> </body> </html> ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=108956&aid=2897990&group_id=8956 |