Hello, I run a stock photo site and yesterday I xferred it to a new host, and the entire site is now broken if you search or click on any category: http://www.turbophoto.com It says: Catchable fatal error: Object of class Pager could not be converted to string in paging.inc.php on line 49 The server I previously ran it on had an older version of PHP, and PHP 5.3 is not agreeing with this code. Are globals not allowed? I'm stumped and stressed about this, while thousands of visitors are seeing this error and going elsewhere. Here's the code from paging.php: function leftPaging() { global $clspg; global $pages; $pagelist = ""; if (trim($clspg) != "") /* this is line 49 */ if ($pages > 1) $pagelist = $clspg->nextprev($_GET['page'], $pages); return $pagelist; } PHP: The class Pager is from an include which is 100 lines- too long to post here. Does anyone know what may be causing the problem? Thank you in advance.
Post lines 40-52 of paging.inc.php and indicate which line is line 49. Also either paste the relevant lines of the class file, or paste the class file into a pastebin-type site and post the URL here.
I think you are trying to use a variable that you want to use as a string is defined in a earlier statement for a class... post more code!
Thanks so much so far. Here's the actual full code: http://www.turbophoto.com/config/class.pager.txt http://www.turbophoto.com/config/paging.inc.txt Here is the long code from class.pager.php <?php class Pager { /*********************************************************************************** * int findStart (int limit) * Returns the start offset based on $_GET['page'] and $limit ***********************************************************************************/ function findStart($limit) { if ((!isset($_GET['page'])) || ($_GET['page'] == "1")) { $start = 0; $_GET['page'] = 1; } else { $start = ($_GET['page']-1) * $limit; } return $start; } /*********************************************************************************** * int findPages (int count, int limit) * Returns the number of pages needed based on a count and a limit ***********************************************************************************/ function findPages($count, $limit) { $pages = (($count % $limit) == 0) ? $count / $limit : floor($count / $limit) + 1; return $pages; } /*********************************************************************************** * string pageList (int curpage, int pages) * Returns a list of pages in the format of "« < [pages] > »" ***********************************************************************************/ function pageList($curpage, $pages) { $page_list = ""; $str = ""; foreach( $_GET as $key=>$value) { if ($key=="message" || $key=="page" || $key=="pagegroup") {} else $str = $str."&".$key."=".$value; } foreach( $_POST as $key=>$value) { if ($key=="message" || $key=="page" || $key=="pagegroup") {} else $str = $str."&".$key."=".$value; } $pagegroup = $_REQUEST['pagegroup']; $limitset = 50; if ($pagegroup== ""){ $pagegroup = 1; } /* Print the first and previous page links if necessary */ /* if (($curpage != 1) && ($curpage)) { $str1 = $str . "&pagegroup=1"; $page_list .= " <a href=\"".$_SERVER['PHP_SELF']."?page=1".$str1."\" title=\"First Page\"><font color=#ff0000>«</font></a> "; } */ $prevgrouppage = ($pagegroup - 1) * ($limitset); if (($prevgrouppage) > 0) { $str1 = $str . "&pagegroup=" . ($pagegroup-1); $spage = ($limitset*($pagegroup-1)) + 1 - $limitset; $page_list .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".($spage).$str1."\" title=\"Previous Page\" class=\"blue_txt\"><b>Previous $limitset Pages |</b></a> "; } $startpage = (($pagegroup - 1) * $limitset); /* Print the numeric page list; make the current page unlinked and bold */ for ($i=$startpage+1; $i<=$pages; $i++) { $str1 = $str . "&pagegroup=" . $pagegroup; if ($i > ($startpage + $limitset)) break; if ($i == $curpage) { $page_list .= "<b>"."<span class=\"links_blue\">".$i." | </span>"."</b>"; } else { $page_list .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i.$str1."\" title=\"Page ".$i."\">"."<span class=\"white_bold\">".$i." | </span>"."</a>"; } $page_list .= " "; } $nextgrouppage = $pagegroup * $limitset; /* Print the Next and Last page links if necessary */ if (($nextgrouppage+1) <= $pages) { $str1 = $str . "&pagegroup=" . ($pagegroup+1); $spage = ($limitset*$pagegroup) + 1; $page_list .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".($spage).$str1."\" title=\"Next PageSet\"><span class=\"white_bold\"><b> Next $limitset Pages</b></span></a> "; } if (($curpage != $pages) && ($pages != 0)) { if (($pages%$limitset) == 0) $str1 = $str . "&pagegroup=" . ($pages/$limitset); else $str1 = $str . "&pagegroup=" . (($pages/$limitset) + 1); $page_list .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".$pages.$str1."\" title=\"Last Page\"></a> "; } $page_list .= "\n"; return $page_list; } /*********************************************************************************** * string nextPrev (int curpage, int pages) * Returns "Previous | Next" string for individual pagination (it's a word!) ***********************************************************************************/ function nextPrev($curpage, $pages) { $next_prev = ""; $page_list = ""; $str = ""; foreach( $_GET as $key=>$value) { if ($key=="message" || $key=="page") {} else $str = $str."&".$key."=".$value; } foreach( $_POST as $key=>$value) { if ($key=="message" || $key=="page") {} else $str = $str."&".$key."=".$value; } if (($curpage-1) <= 0) { $next_prev .= "Previous"; } else { $next_prev .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".($curpage-1).$str."\">Previous</a>"; } $next_prev .= " | "; if (($curpage+1) > $pages) { $next_prev .= "Next"; } else { $next_prev .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".($curpage+1).$str."\">Next</a>"; } $next_prev .= "\n"; return $next_prev; } } ?> PHP:
SOLVED! I just removed the trim() function from line 49. I should have thought of this earlier: if (trim($clspg) != "") - broken in new PHP version if ($clspg != "") - works in new PHP version I don't know how to trim it, but that's ok, I maybe don't need to.
Since $clspg is (probably - it's declared elsewhere in code you don't show) a class, you can't trim it - trim() takes a string argument. You can trim a string you get from $clspg. Even if ($clspg != "") is improper syntax, but it doesn't throw an error. (I doubt it's going to be working correctly. != "" only applies to a string variable.)