athyzafiris Posted June 28, 2008 Share Posted June 28, 2008 Please help as i can't see what the problem is I have the following error Fatal error: Cannot instantiate non-existent class: globalfunctions in /home/mrcastl/public_html/humane/Application.php on line 86 Application file <?php function __autoload($class_name) { require_once 'system/classes/'.$class_name . '.php'; } define("SALUTATIONS", "Mr, Mrs, Miss, Ms, Prof, Doc"); //constants for how an articles body content will get broken down and displayed define("BODY_TEASER_PARAGRAPH_COUNT", 5);//show 3 paragraphs for teaser content define("BODY_PARAGRAPHS_PER_PAGE", 15);//how many paragraps per page to show define("DB_DATE_MASK", "Y-m-d H:i:s");//iso date format mask for MYSQL set_magic_quotes_runtime (0);//set magic quotes to off - ?does this effect all apps on php instance //array of variables created for sharing across pages as a result of an page call $request = array(); $request["error_msg"] = "";//if something goes wrong $request["success_msg"] = "";//if all goes right $request["page_title"] = "";//Default HTML page title $request["site_section"] = "none";//Default site section - mostly will be same as root dir $request["page_meta_desc"] = ""; $request["show_outer_col"] = true; $request["body_class"] = "threecol"; // copy all FORM and URL variables to ATTRIBUTES scope // here, FORM has precendence although this can be over-written later depending on the application's fusebox.xml setting. if(!isset($attributes) || !is_array($attributes)) { $attributes = array(); $attributes = array_merge($_GET,$_POST); } //record if this was a post submission or not if(count($_POST) >= 1){ define("REQUEST_WAS_POST", true); }else{ define("REQUEST_WAS_POST", false); } //set the action - this is what will determine what takes place if (!array_key_exists("action", $attributes)) { $attributes["action"] = "";//default } session_start();//start a sesssion if one not already present //figure out the url path, should we need it $site_root_url = "http://".$_SERVER["SERVER_NAME"]; //require_once("system/templates/category_ids.php"); if(strcasecmp($_SERVER["SERVER_NAME"], "phpscratch.athy.com") == 0){ //database connection 1 code }else{//live //database connection 2 code } $request["gf_obj"] = new GlobalFunctions();//create this object and place in request array ------- LINE 84 that is giving trouble print "here7"; //take into account if there is a port if (isset($_SERVER["SERVER_PORT"]) && ($_SERVER["SERVER_PORT"] != 80)){ $site_root_url = $site_root_url .":".$_SERVER["SERVER_PORT"]; } define("SITE_ROOT_URL", $site_root_url); unset($site_root_url); set_include_path(SITE_FILE_PATH . get_include_path()); //so we can do all includes relative to root if(!isset($_SESSION["is_logged_in"])){ $_SESSION["is_logged_in"] = false; } //log user out if(($_SESSION["is_logged_in"] === true) && ($attributes["action"]=="logout") ){ $_SESSION["is_logged_in"] = false; } ?> Can anyone see what is wrong? If i do a straight include_one or require_once i get synax errors on the GlobalFunctions file but i can not see any syntax errors. Quote Link to comment https://forums.phpfreaks.com/topic/112306-fatal-error-cannot-instantiate-non-existent-class-globalfunctions-in/ Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Share Posted June 28, 2008 i don't see where you are including the file containing the class?? and if you are getting syntax in the class file then post that?? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/112306-fatal-error-cannot-instantiate-non-existent-class-globalfunctions-in/#findComment-576603 Share on other sites More sharing options...
athyzafiris Posted June 28, 2008 Author Share Posted June 28, 2008 i am including it in the autoload function at the top. Please see by the Globalfunctions file that brings up syntax errors if i do a include_one or a require_once class GlobalFunctions{ private $query_runner_obj = null; function __construct(){ $this->query_runner_obj = new QueryRunner(); } /*Simple function that checks if a key exists in an array and if not creates it with the passed argument as default * */ public static function param_set(&$arr,$key,$default=""){ if(!isset($arr[$key])){ $arr[$key] = $default; } } public static function getCategoryName() { $cat_names = array(); $cat_names = $cats_obj->getCat_Name(); return $cat_names; } public function getImageList($filename) { $image = array(); $sql = sprintf("select small_image, large_image, description from gallery_images where directory = '%s' ORDER BY item_id", $filename); $qres_obj = $this->do_query($sql); if( ($qres_obj->get_status() === true) && ($qres_obj->get_record_count() > 0) ) { $result_set = $qres_obj->get_result_set();//get the result set foreach ($result_set as $result_item) { $ret = array(); $ret["small_image"] = $result_item["small_image"]; $ret["large_image"] = $result_item["large_image"]; $ret["description"] = $result_item["description"]; $image[] = $ret; } }//for each else{ throw new Exception("no images in that directory=".$qres_obj->get_status().", erorr msg=". $qres_obj->get_error_message()); } return $image; } /** * Display function to topic listings on places like the homepage, magazine content etc * @param $cats_obj - Categories object * @param $cat_id - category id * @param $articles - array of articles * @param $topic_style - valid css for the div topic */ public static function displayCategoryListing(&$cats_obj,$cat_id, &$articles, $topic_style=""){ $found_one = false; $cat_dir_name = $cats_obj->get_dir_name($cat_id); $cat_name = $cats_obj->get_display_name($cat_id); $cat_id = $cat_id; foreach ($articles as $result_item) {//bit inefficienet this but shouldnt be that bad if($result_item["article_category_id"] == $cat_id){ if(!$found_one){ echo "<div class=\"topic\" style=\"".$topic_style."\" >"; echo "<h3><a href=\"/".$cat_dir_name."\">".$cat_name."</a></h3>"; $found_one = true; } $image = ""; if($result_item["is_free"]){ $image = "<img src=\"/images/free_icon.gif\" alt=\"free content\" class=\"free\"/>"; } echo "<h4>$image<a href=\"/$cat_dir_name/index.php?articleid=${result_item["item_id"]}\">${result_item["title"]}</a></h4>"; echo "<p>${result_item["summary_paragraph"]}...<a href=\"/$cat_dir_name/index.php?articleid=${result_item["item_id"]}\">»</a></p>"; }//if }//foreach if($found_one){ echo "<p><a href=\"/$cat_dir_name/\"><span class=\"red\">more $cat_name »</span></a></p>"; echo "</div><!--topic-->"; }//if }//funct /*Execute a query using the query runner object and return a QueryResult object */ public function do_query($query){ //echo $query; $qres = $this->query_runner_obj->do_query($query); return $qres; } /** *Parses a mysql date time string "yyyy-mm-dd hh:mm:ss" and returns a timestamp value *hh is in 24 hour format *@returns a value generated by mktime function */ public static function parseMySQLDateTime($date) { $year = substr($date, 0, 4); $month = substr($date, 5, 2); $day = substr($date, 8, 2); $hour = substr($date, 11, 2); $minute = substr($date, 14, 2); $second = substr($date, 17, 2); $timestamp = mktime($hour, $minute, $second, $month, $day, $year); return $timestamp; } /** * Truncates strings to show ellipsis if passes string is too big else return the string */ public static function ellipsis($s, $max_length=20){ $ret = $s; $spcIdx = 0;//see later if ( strlen($s) > $max_length ){//needs proccessing $ret = substr($s, 0, ($max_length-3)); //find the last space less than 20 chars in if there is one $ret = strrev($ret); $spcIdx = strpos($ret," "); if ($spcIdx <= 20){ $ret = substr($ret, $spcIdx-strlen($ret)); //$ret = right($ret, strlen($ret)-$spcIdx); } $ret = strrev($ret);//reverse back $ret = $ret."..."; }//if return $ret; }//func /** * Gets hotspot text for the supplied area. * This function * @param name - the name of the hotspot e.g. "aboutus" * @randomize - return one of the possible active items randomly (ignores date ordering) * @returns the latest online hotspot text for the supplied area or empty string */ public function get_hotspot($name, $randomize=false){ $ret = ""; $sql = sprintf("select body from hotspot_area ha join hotspot_item hi on ha.hotspot_area_id = hi.hotspot_area_id join content_item ci on ci.item_id = hi.item_id " . "where ha.hotspot_name = '%s' and workflow_status = 1 and (start_date < now() and end_date > now())" , $name); if($randomize){ //is random }else{//not random so get the latest active one $sql = $sql." order by start_date desc limit 1"; } $qres_obj = $this->do_query($sql); if( ($qres_obj->get_status() === true) && ($qres_obj->get_record_count() > 0) ){ $result_set = $qres_obj->get_result_set();//get the result set $row_index = 1; $row_counter = 0; if($randomize){//get a random column $row_index = rand(1, $qres_obj->get_record_count()); } //if random then will get one for get_record_count() possibilities else will always get first row foreach ($result_set as $result_item) { $row_counter++; //throw new Exception("$row_counter, $row_index"); if($row_index == $row_counter){ $ret = $result_item["body"]; break;//only one row } }//for each }elseif ($qres_obj->get_status() === false){ throw new Exception("bad query to get hotspot, status=".$qres_obj->get_status().", erorr msg=". $qres_obj->get_error_message()); } return $ret; }//funct /* * trims the contents of an assocaitive array * ?does this work for non assoc? */ public static function array_trim(&$arr){ foreach ($arr as $key => $value) { $attributes[$key] = trim($value); } }//funct /** * Checks if the passed list of array keys exist the passed array and are non emtpy i.e. = "" * Used for form submission to check if certain items are present * @returns true or false */ public static function check_fields_exist($arr, $list){ $tok = strtok($list, ","); while ($tok !== false) { if( isset($arr[$tok]) && (!is_array($arr[$tok])) && (!is_object($arr[$tok])) ){ $val = trim(strval($arr[$tok]));//convert to string if(strlen($val) == 0){ return false;//fail } }//if $tok = strtok(",");//get next token }//while return true;//all is good } /** *Wrapper for how db strings are escapes *@param $use_slashes - set to true if addslashes is to be used else set to false if '' is to be used, change default to make things easy if db is changed *@returns the escaped string */ public static function dbEscape($s, $use_slashes=true){ if($use_slashes){ return addslashes($s); }else{ return str_replace("'", "''", $s);// sql server and sybase } }//funct /** *Proccess Form Field String Content *Replaces all non standard ascii chars with numerical entity equivalents e.g. &#xxx; form *Idea is that all fields that will be shown on the web site are escaped with this and placed into the database in *the escaped format. The problem is if argument s is allowed to have html markup. In this case we cant escape html chars e.g. < *so this could break the display page on the site also " if used in an html tag attribute *@returns proccessed string */ public static function escapeFormField($s, $contains_html=false){ $char = ""; $ret = "";//what gets returned for($i=0 ; $i < strlen($s) ; $i++){ $char = substr($s, $i, 1);//get a char at a time $code = ord($char); //character code switch($code){ case 124: { //the | char - dont know why this is special - perhaps mac thing $char = "&#".$code .";"; break; } case 60: { if(!$contains_html)$char = "<"; break; } case 62: { if(!$contains_html)$char = ">"; break; } /*case 39: { if(!$contains_html)$char = "'"; break; }*/ case 34: { if(!$contains_html)$char = """; break; } default:{ if( $code >= 127 ){ $char = "&#".$code .";"; } } } $ret = $ret . $char; }//for return $ret; }//function /*Checks passed in email for validity *@returns true or false */ public static function isEmailValid($email) { if (!(eregi ("^[\'_a-z0-9-]+(\.[\'_a-z0-9-]+)*@[a-z0-9-]+\.[a-z0-9-]+(\.[a-z0-9-]+)*$", $email))) { return false; } return true; }//funct public static function getCountryName() { $row = array(); $sql = "select countryname from iso_country order by countryname"; global $request;//defined in Application.php $gf_obj = $request["gf_obj"];//the global helper object $qres_obj = $gf_obj->do_query($sql); if( ($qres_obj->get_status() === true) && ($qres_obj->get_record_count() > 0) ){ $result_set = $qres_obj->get_result_set();//get the result set foreach ($result_set as $result_item) { $row[] = $result_item["countryname"]; } } else { $row = null; } return $row; } public static function addOnClickEvent($name, $section) { echo "here"; $today = date("D M j G:i:s T Y"); $sql = "insert into hotspot_tracking (date, hotspot_name, page_section) values('".$today."', '".$name."', '".$section."')"; $result = $db->query($sql); if (!$result) {die('Bad Query: ' . mysql_error());} } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112306-fatal-error-cannot-instantiate-non-existent-class-globalfunctions-in/#findComment-576632 Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Share Posted June 28, 2008 what syntax errors do you get when you use include_once?? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/112306-fatal-error-cannot-instantiate-non-existent-class-globalfunctions-in/#findComment-576922 Share on other sites More sharing options...
athyzafiris Posted June 29, 2008 Author Share Posted June 29, 2008 I get the following error Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/mrcastl/public_html/humane/system/classes/GlobalFunctions.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/112306-fatal-error-cannot-instantiate-non-existent-class-globalfunctions-in/#findComment-576999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.