Problem call to a member function on a non-object
03-15-2008, 12:22 AM
|
Problem call to a member function on a non-object
|
Posts: 4
Name: Akie Kotabe
|
Hi, i got the prolem with /public_html/includes/common_functions.php on line 161here's the code:
PHP Code:
<? function redirect($url) { echo "<script language=\"javascript\">"; echo "window.location.href=\"$url\""; echo "</script>"; exit(); }
function reload() { echo "<script language=\"javascript\">"; echo "window.location.reload()"; echo "</script>"; exit(); }
function validGetVar($getVal) { $damStr = "{/,',?,&,\"}"; if(ereg($damStr,$getVal)) return false; return true; }
function inDateStr($strDate) { $strDate = trim($strDate); list($day, $month, $year) = split('[/.-]', $strDate); $strDate = "$year-$month-$day"; return $strDate; }
function outDateStr($strDate,$sep="/") { $strDate = trim($strDate); list($year, $month, $day) = split('[/.-]', $strDate); $strDate = "$day/$month/$year"; return $strDate; }
function cutString($str,$sPos,$ePos) { $result = NULL; while($str[$ePos]!=" " && $str[$ePos]!=NULL) $ePos--; $result = substr($str,$sPos,$ePos); return $result; }
function extFile($strFile) { $ext = NULL; $strFile = trim($strFile); $splitStr = split("~",str_replace(".","~",$strFile)); sizeof($splitStr); if(sizeof($splitStr)>1) $ext = $splitStr[sizeof($splitStr)-1]; return $ext; }
function _POST($value) { global $_GET, $_POST, $HTTP_POST_VARS,$HTTP_GET_VARS; if (isset($_POST["$value"])) return $_POST["$value"]; elseif (isset($HTTP_POST_VARS["$value"])) return $HTTP_POST_VARS["$value"]; elseif (isset($_GET["$value"])) return $_GET["$value"]; elseif (isset($HTTP_GET_VARS["$value"])) return $HTTP_GET_VARS["$value"]; else return NULL; } function _SESSION($session_name) { global $_SESSION,$HTTP_SESSION_VARS; if (isset($_SESSION["$session_name"])) return $_SESSION["$session_name"]; elseif (isset($HTTP_SESSION_VARS["$session_name"])) return $HTTP_SESSION_VARS["$session_name"]; else return NULL; }
function getStars($class=1) { global $_IMG_DIR;
$star = NULL; settype($class,"integer"); for($i=0;$i<$class;$i++) { $star .= "<img src=\"$_IMG_DIR/star.gif\">"; } return $star; }
function numOpt($item=NULL,$label=NULL,$low=2,$high=5) { $strOpt = "<option value=\"\" checked>$label</option>"; for($i=$low;$i<=$high;$i++) { $strOpt .= "<option value=$i " ; if($i==$item) $strOpt .=" selected "; $strOpt .= "> ".$i." </option>"; } return $strOpt; }
function priceOpt($item=NULL,$low=15,$high=165,$level=15) { global $define; $strOpt = "<option value=\"\" checked>"; $strOpt .= $define["asia_gia"]."</option>"; $value = $define["asia_duoi"] . " - " . $low; $strOpt .= "<option value=\"$value\" " ; if($value==$item) $strOpt .=" selected "; $strOpt .= ">$value</option>"; for($i=$low;$i<$high;$i+=$level) { if($i+$level<$high) $value = $i . " - " . ($i+$level-1); else $value = $i . " - " . ($i+$level); $strOpt .= "<option value=\"$value\" " ; if($value==$item) $strOpt .=" selected "; $strOpt .= ">$value</option>"; } $value = $define["asia_tren"] . " - " . $high; $strOpt .= "<option value=\"$value\" " ; if($value==$item) $strOpt .=" selected "; $strOpt .= ">$value</option>"; return $strOpt; }
function roomOpt($lodging) { $opt = new option(); $strRoom = $opt->optionvalue("vnws_lodging","lodging_occupancy","lodging_id=$lodging"); $rooms = split("~",$strRoom); $strOpt = NULL; for($i=0;$i<sizeof($rooms);$i++) { $name = $opt->optionvalue("vnws_roomtype","roomtype_name","roomtype_id='".$rooms[$i]."'"); $strOpt .= '<option value="'.$name.'">'.$name.'</option>'; } return $strOpt; }
// Define define('FILE_NOT_EXIST','Lỗi! File không tồn tại'); define('ERROR_FILE_NOT_WRITEABLE','Lỗi! Không thể ghi file'); // End define
function openFile($file) { if(!is_file($file)) { echo FILE_NOT_EXIST; return NULL; } $file_array = file($file); $content = implode('',$file_array); return $content; }
function saveFile($file,$content) { global $messageStack; if(!is_writeable($file)) { $messageStack->reset(); $messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE,$file),'error'); echo $messageStack->output(); return false; } $new_file = fopen($file,'w'); $content = stripslashes($content); fwrite($new_file,$content,strlen($content)); fclose($new_file); return true; }
function validImage($src,$name=NULL) { if($name==NULL) $name = $src; $ext = strtolower(extFile($name)); $listExt = array('jpg','gif','png','bmp'); if(!in_array($ext,$listExt)) return false; $fsize = @filesize($src)/1024/1024; if(($fsize<=0)||($fsize>1.95)) return false; return true; }
function imageSize($img,$maxW=100,$maxH=100) { if(!validImage($img)) return false; if($maxW<=0||$maxH<=0) return false; $sizeOut = array(); $imgSize = getimagesize($img); $sizeOut = $imgSize; $x_ratio = $maxW/$imgSize[0]; $y_ratio = $maxH/$imgSize[1]; $ratio = min($x_ratio,$y_ratio); if(($imgSize[0]>$maxW)||($imgSize[1]>$maxH)) { $sizeOut[0] = $imgSize[0]*$ratio; $sizeOut[1] = $imgSize[1]*$ratio; } return $sizeOut; } ?>
Can anyone help ?? Thanks alot.
|
|
|
|
03-15-2008, 01:43 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 195
Name: Jim
Location: Ohio
|
$messageStack->reset();
The $messageStack var is not an object type
You need to make sure the object is created first
|
|
|
|
03-15-2008, 02:09 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 4
Name: Akie Kotabe
|
Sorry i'm a newbie in PHP so can you tell me more details like how to fix it ??
Thank you very much for your help.
|
|
|
|
03-15-2008, 02:22 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
It appears that $messageStack is supposed to be an instance of an object, but I don't see it initialized anywhere. From your code I can't tell what object it is supposed to be an instance of, is there a class anywhere in your code called MessageStack or Stack?
If it is supposed to be a stack I've never heard of a stack datastructure built into php so there must be one in your code somewhere. Check your other files.
To clarify what jim said, the -> operator works like the dot operator in java and c++. It's used to access methods and member variables of an object. It has no meaning in the context of a non-object.
Last edited by NullPointer; 03-15-2008 at 02:24 AM..
|
|
|
|
03-15-2008, 03:02 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 4
Name: Akie Kotabe
|
Hi there's a functions file that have $messageStack
PHP Code:
<? function cutString($str,$sPos,$ePos) { $result = NULL; while($str[$ePos]!=" " && $str[$ePos]!=NULL) $ePos--; $result = substr($str,$sPos,$ePos); return $result; }
function formatStringDefineIn($str) { $str = str_replace('"','``',$str); return $str; }
function formatStringDefineOut($str) { $str = str_replace('``','"',$str); return $str; } function removeHtmlTag($str,$tag) { $strCopy = strtolower($str); $tag = strtolower($tag); $len = strlen($strCopy); $sPos = strpos($strCopy,"<$tag"); $ePos = $sPos+1; while(($ePos<$len)&&($strCopy[$ePos]!=">")) { $ePos++; } $str = substr($str,0,$sPos).substr($str,$ePos+1); return $str; }
function inDateStr($strDate) { $strDate = trim($strDate); list($day, $month, $year) = split('[/.-]', $strDate); $strDate = "$year-$month-$day"; return $strDate; } function outDateStr($strDate) { $strDate = trim($strDate); list($year, $month, $day) = split('[/.-]', $strDate); $strDate = "$day/$month/$year"; return $strDate; }
function getStars($class=1) { $star = NULL; for($i=0;$i<$class;$i++) { $star .= '<img src="images/star.gif">'; } return $star; }
function starOpt($item=NULL,$low=1,$high=5) { $strOpt = "<option value=\"\" checked>"; $strOpt .= "-- Stars --</option>"; for($i=$low;$i<=$high;$i++) { $strOpt .= "<option value=$i " ; if($i==$item) $strOpt .=" selected "; $strOpt .= ">".$i." Stars</option>"; } return $strOpt; }
function createPropertyForm($sufTblName,$proStr) { $pros = split("~",$proStr); echo '<table cellpadding="5" cellspacing="0">'; $sql = new mysql(); $sql->set_query("vnws_".$sufTblName,"*",NULL,"ORDER BY ".$sufTblName."_order"); while($sql->set_farray()) { $id = $sql->farray[$sufTblName."_id"]; $name = $sql->farray[$sufTblName."_name"]; $proValue = NULL; for($i=0;$i<sizeof($pros);$i++) { list($proN,$proV) = split("::",$pros[$i]); if($proN==$id) $proValue = $proV; } echo '<tr><td class="rowform" nowrap>'.$name.':</td><td class="rowform">'; echo '<input name="proValue" size="30" value="'.$proValue.'" class="textbox" onKeyUp="telexingVietUC(this)">'; echo '</td></tr>'; echo '<input type="hidden" name="proID" value="'.$id.'">'; } echo '</table>'; }
function createOccupancyNameForm($occStr) { $occs = split("~",$occStr); $sql = new mysql(); $sql->set_query("vnws_occupancy","*",NULL,"ORDER BY occupancy_order"); $ttRws = $sql->nRows; $nCols = 3; $numRws = (round($ttRws/$nCols)>0) ? round($ttRws/$nCols) : 1; if($ttRws/$numRws>$nCols) $numRws++; $wCols = floor(100/$nCols); $count = 1; echo '<table cellpadding="5" cellspacing="0" width="100%">'; echo '<tr><td class="rowform" width="'.$wCols.'%" valign="top">'; while($sql->set_farray()) { $id = $sql->farray["occupancy_id"]; $name = $sql->farray["occupancy_name"]; $checked = NULL; if(in_array($id,$occs)) $checked = "checked"; echo '<div><input type="checkbox" name="occName" '.$checked.' value="'.$id.'">'.$name.'</div>'; if($count%$numRws == 0) echo '</td><td class="rowform" width="'.$wCols.'%" valign="top">'; $count++; } echo '</td></tr></table>'; }
function createOccupancyForm($lodging_id,$occStr) { $occs = split("~",$occStr); $opt = new option(); $occNames = $opt->optionvalue("vnws_lodging","lodging_occupancy","lodging_id='".$lodging_id."'"); $occNames = split("~",$occNames); $ttRws = sizeof($occNames); echo '<table cellpadding="2" cellspacing="0" width="100%">'; for($i=0;$i<$ttRws;$i++) { $oname = $opt->optionvalue("vnws_occupancy","occupancy_name","occupancy_id='".$occNames[$i]."'"); $checked = NULL; $oValue = NULL; for($j=0;$j<sizeof($occs);$j++) { list($oN,$oV) = split("::",$occs[$i]); if($oN==$occNames[$i]) { if($oV!=YES) $oValue = $oV; $checked = "checked"; } } echo '<tr><td nowrap width="10%">'.$oname.'</td>'; echo '<td>: <input name="oValue" size="11" value="'.$oValue.'" class="textbox"></td></tr>'; echo '<input type="hidden" name="oID" value="'.$occNames[$i].'">'; } echo '</table>'; }
function occupancyViewing($sufTblName,$occStr) { $opt = new option(); $occs = split("~",$occStr); echo '<table cellpadding="2" cellspacing="0" width="100%">'; for($i=0;$i<sizeof($occs);$i++) { list($occN,$occV) = split("::",$occs[$i]); $name = $opt->optionvalue("vnws_".$sufTblName,$sufTblName."_name",$sufTblName."_id='".$occN."'"); echo '<tr height="25"><td nowrap width="5%" style="padding-left:25px">'.$name.'</td>'; echo '<td width="90%">: <font color="#FF6600">'.$occV.'</font></td></tr>'; } echo '</table>'; }
function occupancyNameViewing($occStr) { $opt = new option(); $occs = split("~",$occStr); $ttRws = sizeof($occs); $nCols = 2; $numRws = (round($ttRws/$nCols)>0) ? round($ttRws/$nCols) : 1; if($ttRws/$numRws>$nCols) $numRws++; $wCols = floor(100/$nCols); $count = 1; echo '<table cellpadding="5" cellspacing="0" width="100%">'; echo '<tr><td width="'.$wCols.'%" valign="top" style="color:#003399"><ul>'; for($i=0;$i<sizeof($occs);$i++) { $name = $opt->optionvalue("vnws_occupancy","occupancy_name","occupancy_id='".$occs[$i]."'"); echo "<li>$name</li>"; if($count%$numRws == 0) echo '</ul></td><td width="'.$wCols.'%" valign="top" style="color:#003399"><ul>'; $count++; } echo '</ul></td></tr></table>'; }
function outPermisionStr($strPer) { $strPer = trim($strPer); $usrper = array(); list($usrper["canEdit"],$usrper["canAdd"],$usrper["canDel"],$usrper["canUser"]) = split('_',$strPer); return $usrper; }
function setPermisionChecked($perm) { $permChked = array(); if($perm["canEdit"]==YES) $permChked["cEdit"] = "checked"; if($perm["canAdd"]==YES) $permChked["cAdd"] = "checked"; if($perm["canDel"]==YES) $permChked["cDel"] = "checked"; if($perm["canUser"]==YES) $permChked["cUser"] = "checked"; return $permChked; }
// Parse the data used in the html tags to ensure the tags will not break function parse_input_field_data($data, $parse) { return strtr(trim($data), $parse); }
function output_string($string, $translate = false, $protected = false) { if ($protected == true) { return htmlspecialchars($string); } else { if ($translate == false) { return parse_input_field_data($string, array('"' => '"')); } else { return parse_input_field_data($string, $translate); } } }
//File function delFile($file) { if(file_exists($file)) @$ok = unlink($file); } function upLoad($userFile,$fileName) { if(file_exists($userFile)) { $upFile = "../$fileName"; move_uploaded_file($userFile,$upFile); } }
//Redirect to "$url" address function redirect($url) { if(!headers_sent()) { header("Location: $url"); } else { echo "<script language=javascript>location.href='".$url."'</script>"; } exit(); }
//Check a varriable function not_null($value) { if (is_array($value)) { if (sizeof($value) > 0) { return true; } else { return false; } } else { if ((is_string($value) || is_int($value)) && ($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) { return true; } else { return false; } } }
// loc1 is the path on the computer to the base directory that may be moved define('loc1', '', true); // copy a directory and all subdirectories and files (recursive) // void dircpy( str 'source directory', str 'destination directory' [, bool 'overwrite existing files'] ) function dircpy($source, $dest, $overwrite = false) { if($handle = opendir(loc1.$source)) { // if the folder exploration is sucsessful, continue $dest_path = loc1.$dest; if(@!is_dir($dest_path)) mkdir($dest_path,0777); while(false!==($file = readdir($handle))) { // as long as storing the next file to $file is successful, continue if($file != '.' && $file != '..') { $path = "$source/$file"; if(is_file(loc1.$path)) { if(!is_file(loc1."$dest/$file") || $overwrite) if(!@copy(loc1.$path, loc1."$dest/$file")) { echo '<font color="red">File ('.$path.') could not be copied, likely a permissions problem.</font>'; } } elseif(is_dir(loc1.$path)) { if(!is_dir("$dest_path/$file")) mkdir("$dest_path/$file",0777); // make subdirectory before subdirectory is copied dircpy($path, "$dest/$file", $overwrite); //recurse! } } } closedir($handle); } } // end of dircpy()
//This function used to remove directory function removeDir($source) { global $messageStack, $tep_remove_error;
if (isset($tep_remove_error)) $tep_remove_error = false;
if (is_dir($source)) { $dir = dir($source); while ($file = $dir->read()) { if(($file != '.')&&($file != '..')) { if(is_writeable("$source/$file")) { removeDir("$source/$file"); } else { $messageStack->add(sprintf(ERROR_FILE_NOT_REMOVEABLE, "$source/$file"), 'error'); $tep_remove_error = true; } } } $dir->close();
if (is_writeable($source)) { rmdir($source); } else { $messageStack->add(sprintf(ERROR_DIRECTORY_NOT_REMOVEABLE, $source), 'error'); $tep_remove_error = true; } } else { if (is_writeable($source)) { unlink($source); } else { $messageStack->add(sprintf(ERROR_FILE_NOT_REMOVEABLE, $source), 'error'); $tep_remove_error = true; } } } //End romoveDir function
function formatFileName($fname) { $abc='abcdefghijklmnopqrstvuxywz._0123456789'; settype($fname,'string'); $fname = strtolower($fname); $fname = str_replace(" ","",$fname); $len=strlen($fname); for($i=0;$i<$len;$i++) { if(!strstr($abc,$fname[$i])) $fname=str_replace($fname[$i],'_',$fname); } return $fname; } function extFile($strFile) { $ext = NULL; $strFile = trim($strFile); $splitStr = split("~",str_replace(".","~",$strFile)); sizeof($splitStr); if(sizeof($splitStr)>1) $ext = $splitStr[sizeof($splitStr)-1]; return $ext; }
function validImage($src,$name=NULL) { if($name==NULL) $name = $src; $ext = strtolower(extFile($name)); $listExt = array('jpg','gif','png','bmp'); if(!in_array($ext,$listExt)) return false; $fsize = @filesize($src)/1024/1024; if(($fsize<=0)||($fsize>1.95)) return false; return true; }
function icon_img($fimg='') { if(!is_file("../$fimg")||($fimg=="")) { $icon_img = $icon_error; } else { $icon_img = "images/".extFile($fimg)."gif"; } return $icon_img; } function imageSize($img,$maxW=100,$maxH=100) { if(!validImage($img)) return false; if($maxW<=0||$maxH<=0) return false; $sizeOut = array(); $imgSize = getimagesize($img); $sizeOut = $imgSize; $x_ratio = $maxW/$imgSize[0]; $y_ratio = $maxH/$imgSize[1]; $ratio = min($x_ratio,$y_ratio); if(($imgSize[0]>$maxW)||($imgSize[1]>$maxH)) { $sizeOut[0] = $imgSize[0]*$ratio; $sizeOut[1] = $imgSize[1]*$ratio; } return $sizeOut; }
function imageSrc($img,$file_type) { $imgSrc = false; if($file_type=="jpeg") $file_type = 'jpg'; switch($file_type) { case 'jpg': if(function_exists("imagecreatefromjpeg")) { $imgSrc = imagecreatefromjpeg("$img"); } break; case 'gif': if(function_exists("imagecreatefromgif")) { $imgSrc = imagecreatefromgif("$img"); } break; case 'png': if(function_exists("imagecreatefrompng")) { $imgSrc = imagecreatefrompng("$img"); } break; case 'bmp': if(function_exists("imagecreatefromwbmp")) { $imgSrc = imagecreatefromwbmp("$img"); } break; } return $imgSrc; }
function imageOut($file_type,$thumb,$pathOut=NULL) { $imgOut = NULL; $func = NULL; if($file_type=="jpg"||$file_type=="jpeg") { $quality=100; if(function_exists("imagejpeg")) $image = imagejpeg($thumb,$pathOut,$quality); } if($file_type=="gif"||$file_type=="bmp") $func = "imagegif"; if($file_type=="png") $func = "imagepng";
if(function_exists("$func")) $imgOut = $func($thumb,$pathOut); return $imgOut; }
function imageCopyResize($image,$xSize,$ySize,$chgScale="NO",$new_image_path=NULL) { if(!file_exists($image)) return "File not exist"; if($xSize==0||$ySize==0) return "At the leat one pair of size is 0"; $width = 0; $height = 0; $size = getimagesize($image); $ratio = min($xSize/$size[0],$ySize/$size[1]); if($chgScale!="NO") { $width = $xSize; $height = $ySize; } elseif($ratio < 1) { $width = ceil($size[0]*$ratio); $height = ceil($size[1]*$ratio); } if(($width>0)&&($width!=$size[0])&&($height>0)&&($height!=$size[1])) { $file_type = strtolower(extFile($image)); $imgSrc = imageSrc($image,$file_type); if($imgSrc=="Unknown") return "Unknown image format: $file_type"; $pathOut = ($new_image_path==NULL) ? $image : $new_image_path; $thumb = imagecreatetruecolor($width, $height); imagecopyresampled($thumb,$imgSrc,0,0,0,0,$width,$height,$size[0],$size[1]); $imgOut = imageOut($file_type,$thumb, $pathOut); imagedestroy($imgSrc); imagedestroy($thumb); } else if($new_image_path!=NULL) { copy($image,$new_image_path); } return $imgOut; }
// Define define('FILE_NOT_EXIST','Lỗi! File không tồn tại'); define('ERROR_FILE_NOT_WRITEABLE','Lỗi! Không thể ghi file'); // End define
function openFile($file) { if(!is_file($file)) { echo FILE_NOT_EXIST; return NULL; } $file_array = file($file); $content = implode('',$file_array); return $content; }
function saveFile($file,$content) { global $messageStack; if(!is_writeable($file)) { $messageStack->reset(); $messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE,$file),'error'); echo $messageStack->output(); return false; } $new_file = fopen($file,'w'); $content = stripslashes($content); fwrite($new_file,$content,strlen($content)); fclose($new_file); return true; }
function _POST($value) { global $_GET, $_POST, $HTTP_POST_VARS,$HTTP_GET_VARS; if (isset($_POST["$value"])) return $_POST["$value"]; elseif (isset($HTTP_POST_VARS["$value"])) return $HTTP_POST_VARS["$value"]; elseif (isset($_GET["$value"])) return $_GET["$value"]; elseif (isset($HTTP_GET_VARS["$value"])) return $HTTP_GET_VARS["$value"]; else return ; } function _SESSION($session_name) { global $_SESSION,$HTTP_SESSION_VARS; if (isset($_SESSION["$session_name"])) return $_SESSION["$session_name"]; elseif (isset($HTTP_SESSION_VARS["$session_name"])) return $HTTP_SESSION_VARS["$session_name"]; else return ; } ?>
|
|
|
|
03-15-2008, 03:45 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
I just did a google search for messageStack and found some oscommerce code that uses messageStack.. do you have a file somewhere called message_stack.php?
|
|
|
|
03-15-2008, 04:07 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 4
Name: Akie Kotabe
|
Thanks you all i finally find out what made that problem. Actually it's my friend problem  after searching and view all his files i can see that he hasn't got any file call messageStack after that i checked some other files and find out the real problem is in his footer.php code there're a class that try to call non-object type so i del it and the problem has been solved.
Thanks again for your helpful
Last edited by kotabe; 03-15-2008 at 04:09 AM..
|
|
|
|
03-15-2008, 04:46 AM
|
Re: Problem call to a member function on a non-object
|
Posts: 195
Name: Jim
Location: Ohio
|
Sorry, it is best to know all the programmer jargon first.
An object is a data type:
http://us2.php.net/manual/en/language.types.php
Click the Objects link
|
|
|
|
|
« Reply to Problem call to a member function on a non-object
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|