pwired Posted June 18, 2014 Posted June 18, 2014 Hi I have following code below and this line: return '<ul>'.do_print_categories_list(explode("\n", $cats), $stack=array(0), $arr=array(), $cat_params).'</ul>'; throws following warning: Strict Standards: Only variables should be passed by reference in /function.list_categories.php on line 32 I did my home work with google and found 2 possible causes: 1.You get the report when you are trying to use a reference as an argument to function,without storing it at variable first. 2. In php 5.xx you are not allowed to change the return value of a function. So far my efforts to change the code with these 2 hints are without success but maybe someone with more php expierence can see what needs to be changed. <?php /** * ------------------------------------------------------------- * File: function.list_categories.php * Type: function * Name: list_categories * Purpose: print out the comment form * * @param string after * @param string before * ------------------------------------------------------------- */ function smarty_function_list_categories($params) //, &$smarty) { $cat_params = array( 'ild'=>'<li>','ird'=>"</li>\n", 'old'=>"<ul>\n",'ord'=>"</ul>\n", 'name' => isset($params['name'])? $params['name'] : '', 'selected' => array() ); //list($catId) = each($categories); $cat_params = array_merge($cat_params, $params); // makese 'selected' an arr $cat_params['selected'] = (array)$params['selected']; //echo "<pre>" . print_r(entry_categories_get()) . "</pre>"; if (file_exists(CONTENT_DIR . 'categories.txt')) { $cats = trim(io_load_file(CONTENT_DIR . 'categories.txt')); this line => return '<ul>'.do_print_categories_list(explode("\n", $cats), $stack=array(0), $arr=array(), $cat_params).'</ul>'; } else { global $lang; $content = '<a href="'.BLOG_BASEURL.'">Unfiled</a>'; if (isset($lang['admin']['entry']['publish']['nocategories'])) $content = $lang['admin']['entry']['publish']['nocategories']; return '<ul><li>' . $content .'</li></ul>' ; } //<label><input name="cats[{$catId}]" //{if (bool)array_intersect(array($catId),$categories) } //checked="checked"{/if} type="checkbox" /> {$cat} </label><br /> }
Craig Posted June 18, 2014 Posted June 18, 2014 Is that blue highlighted line, line 32? Try it like this instead: return '<ul>'.do_print_categories_list(explode("\n", $cats), array(0), array(), $cat_params).'</ul>'; 1
pwired Posted June 19, 2014 Author Posted June 19, 2014 Hi Craig a Rodway, thanks for the reply, tried your modification but threw another warning. But it definitely had to be in that direction, same as the hints I found on the net. (You get the report when you are trying to use this reference as an argument to function, without storing it at variable first.) So this time I tried to define everything in that line outside of it and that seems to work, warning messages no longer popup I changed, return '<ul>'.do_print_categories_list(explode("\n", $cats), $stack=array(0), $arr=array(), $cat_params).'</ul>'; into: $exploded = explode("\n", $cats);$stack=array(0);$arr=array();return '<ul>'.do_print_categories_list($exploded, $stack, $arr, $cat_params).'</ul>'; Being only a php rookie I feel good about this Oh and if you look with google, you'll be amazed how many times this warning message pops up "Strict Standards: Only variables should be passed by reference in . . ." 1
Craig Posted June 19, 2014 Posted June 19, 2014 Yes, I've come up against that a couple of times myself but in slightly different situations. Glad you managed to sort it 1
Recommended Posts