sagnik Posted December 7, 2018 Posted December 7, 2018 Hi, I've some classes which use the spaceship (<=>) operator as a callback for usort() to sort an associative array by the value of a key. Everything is working fine in my localhost with Apache HTTPD 2.4.23, PHP 7.1.1 running on Windows 10. But after I've uploaded the website to HelioHost, I've got the following error: Parse error: syntax error, unexpected '<' in /home/sgn/public_html/careers4you/config/classes/Careers4You/User/Users.php on line 120 Here is the class: <?php namespace Careers4You\User; session_start(); use \SGNetworks as sgn; use \SGNetworks\SGNErrors as sgne; class Users extends sgn\SGNDatabase{ private $db; private $sgne; const table = "users"; private $tbl; private $sgn; private $sgna; private $uid; function __construct(){ $this->db=parent::getDatabase("accounts"); $this->sgne=new sgn\SGNError; $this->tbl=self::table; $this->sgn=new sgn\SGNetworks; $this->sgna=new sgn\SGNAccounts; $this->uid=$_SESSION['sgn-login_uid']; } private function sort_array($array,$k,$order="ASC"){ $order=strtolower($order); if($order=="asc"){ // Ascending Order usort($array, function($item1, $item2){ return $item1[$k] <=> $item2[$k]; }); } elseif($order=="desc"){ // Descending Order usort($array, function($item1, $item2){ return $item2[$k] <=> $item1[$k]; }); } else { // Ascending Order usort($array, function($item1, $item2){ return $item1[$k] <=> $item2[$k]; }); } return $array; } function isJson($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } function getUsersCount($type='all'){ $type=filter_data($type,$this->db); if($type=='normal') $cond=" WHERE status='1'"; elseif($type=='banned') $cond=" WHERE status='0'"; $s="SELECT count(id) FROM {$this->tbl}{$cond}"; if($q=db_query($s,$this->db)){ if(db_num_rows($q)>0) return db_fetch_row($q)[0]; } else { $this->sgne->triggerError($this->sgne->processError(sgne::COMMON_ERRORS['SQL_ERROR'])); } } function getUsers($type='all',$sort="timestamp",$order='ASC',$offset=0,$limit=20){ $type=filter_data($type,$this->db); $sort=filter_data($sort,$this->db); $order=filter_data($order,$this->db); $offset=(!is_numeric($offset))?0:$offset; $limit=(!is_numeric($limit))?"":" LIMIT {$offset}, {$limit}"; if($type=='normal') $cond=" WHERE status='1'"; elseif($type=='banned') $cond=" WHERE status='0'"; else $cond=" WHERE status='1'"; $s="SELECT * FROM {$this->tbl}{$cond} ORDER BY {$sort} {$order}{$limit}"; if($q=db_query($s,$this->db)){ if(db_num_rows($q)>0){ $result=array(); while($r=db_fetch_assoc($q)){ $r['fname']=$this->sgna->getUserPersonalProfile('fname',$r['uid']); $r['mname']=$this->sgna->getUserPersonalProfile('mname',$r['uid']); $r['lname']=$this->sgna->getUserPersonalProfile('lname',$r['uid']); $r['dp']=$this->sgna->getUserPersonalProfile('dp',$r['uid']); $r['dp_mime']=$this->sgna->getUserPersonalProfile('dp_mime',$r['uid']); if($r['mname']) $r['name']=$r['fname']." ".$r['mname']." ".$r['lname']; else $r['name']=$r['fname']." ".$r['lname']; $r['dp_image']=(!$r['dp'])?"":bin2file($r['dp'],$r['dp_mime']); array_push($result,$r); } return $result; } } else { $this->sgne->triggerError($this->sgne->processError(sgne::COMMON_ERRORS['SQL_ERROR'])); } } function getUser($id,$f="*"){ $id=filter_data($id,$this->db); $f=filter_data($f,$this->db); $get=$f; if($f=='full_name' || $f=='dp') $f='uid'; if(is_numeric($id)){ $s="SELECT {$f} FROM {$this->tbl} WHERE id='{$id}' OR uid='{$id}'"; if($q=db_query($s,$this->db)){ if(db_num_rows($q)>0){ $r=db_fetch_assoc($q); $r['fname']=$this->sgna->getUserPersonalProfile('fname',$r['uid']); $r['mname']=$this->sgna->getUserPersonalProfile('mname',$r['uid']); $r['lname']=$this->sgna->getUserPersonalProfile('lname',$r['uid']); $r['full_name']=(!$r['mname'])?"{$r['fname']} {$r['lname']}":"{$r['fname']} {$r['mname']} {$r['lname']}"; $r['dp']=$this->sgna->getUserPersonalProfile('dp',$r['uid']); $r['dp_mime']=$this->sgna->getUserPersonalProfile('dp_mime',$r['uid']); if($r['mname']) $r['name']=$r['fname']." ".$r['mname']." ".$r['lname']; else $r['name']=$r['fname']." ".$r['lname']; $r['dp_image']=(!$r['dp'])?"":bin2file($r['dp'],$r['dp_mime']); if($r['experience']){ $r['experience']=json_decode(defilter_data($r['experience'],$this->db),true); usort($r['experience'], function($item1, $item2){ return $item2['date'] <=> $item1['date']; }); $r['experience']=json_encode($r['experience'],JSON_NUMERIC_CHECK); } if($r['education']){ $r['education']=json_decode(defilter_data($r['education'],$this->db),true); usort($r['education'], function($item1, $item2){ return $item2['date'] <=> $item1['date']; }); $r['education']=json_encode($r['education'],JSON_NUMERIC_CHECK); } if($r['skills']){ $r['skills']=json_decode(defilter_data($r['skills'],$this->db),true); usort($r['skills'], function($item1, $item2){ return $item2['date'] <=> $item1['date']; }); $r['skills']=json_encode($r['skills'],JSON_NUMERIC_CHECK); } return ($get!="*")?$r[$get]:$r; } } else { $this->sgne->triggerError($this->sgne->processError(sgne::COMMON_ERRORS['SQL_QUERY_ERROR'])); } } else { $this->sgne->triggerError(sgne::COMMON_ERRORS['INVALID_PARAM_VALUE']['msg'], sgne::COMMON_ERRORS['INVALID_PARAM_VALUE']['code'],"Author ID OR AID"); } } function updateProfile($about,$addr1,$addr2,$street,$locality,$district,$zip,$city,$state,$country,$phone,$email,$website,$dob,$sex,$relationship,$hobbies,$experience,$qualifications,$skills){ $about=filter_data($about,$this->db); $addr1=filter_data($addr1,$this->db); $addr2=filter_data($addr2,$this->db); $street=filter_data($street,$this->db); $locality=filter_data($locality,$this->db); $district=filter_data($district,$this->db); $zip=filter_data($zip,$this->db); $city=filter_data($city,$this->db); $state=filter_data($state,$this->db); $country=filter_data($country,$this->db); $phone=filter_data($phone,$this->db); $email=filter_data($email,$this->db); $website=filter_data($website,$this->db); $dob=filter_data($dob,$this->db); $sex=filter_data($sex,$this->db); $relationship=filter_data($relationship,$this->db); $hobbies=filter_data($hobbies,$this->db); $experience=filter_data($experience,$this->db); $qualifications=filter_data($qualifications,$this->db); $skills=filter_data($skills,$this->db); $s="UPDATE {$this->tbl} SET aboutme='{$about}', address1='{$addr1}', address2='{$addr2}', street='{$street}', locality='{$locality}', district='{$district}', zip='{$zip}', city='{$city}', state='{$state}', country='{$country}', phone='{$phone}', email='{$email}', website='{$website}', dob='{$dob}', sex='{$sex}', relationship='{$relationship}', hobbies='{$hobbies}', experience='{$experience}', education='{$qualifications}', skills='{$skills}' WHERE uid='{$this->uid}'"; if(db_query($s,$this->db)) return true; else return false; } function getProfileHeading($id){ $id=filter_data($id,$this->db); if(is_numeric($id)){ $s="SELECT experience,education FROM {$this->tbl} WHERE uid='{$id}' OR id='{$id}'"; if($q=db_query($s,$this->db)){ if(db_num_rows($q)==1){ $r=db_fetch_assoc($q); $heading=""; if(!empty($r['experience'])){ $experience=json_decode(defilter_data($r['experience'],$this->db),true); usort($experience, function($item1, $item2){ return $item2['date'] <=> $item1['date']; }); $mostRecent=0; $mostRecentArray=""; foreach($experience as $exp){ $curDate = strtotime($exp['date']); if($curDate > $mostRecent) { $mostRecent = $curDate; $mostRecentArray=$exp; } } if(!empty($mostRecentArray['name']) && !empty($mostRecentArray['company'])) $heading="{$mostRecentArray['name']}, {$mostRecentArray['company']}"; elseif(!empty($mostRecentArray['name'])) $heading=$mostRecentArray['name']; } elseif(!empty($r['education'])){ $education=json_decode(defilter_data($r['education'],$this->db),true); usort($education, function($item1, $item2){ return $item2['date'] <=> $item1['date']; }); $mostRecent=0; $mostRecentArray=""; foreach($education as $edu){ $curDate = strtotime($edu['date']); if($curDate > $mostRecent) { $mostRecent = $curDate; $mostRecentArray=$edu; } } if(!empty($mostRecentArray['name']) && !empty($mostRecentArray['institution'])) $heading="{$mostRecentArray['name']}, {$mostRecentArray['institution']}"; elseif(!empty($mostRecentArray['name'])) $heading=$mostRecentArray['name']; elseif(!empty($mostRecentArray['institution'])) $heading="Student of {$mostRecentArray['institution']}"; } elseif(!empty($r['skills'])){ $skills=json_decode(defilter_data($r['skills'],$this->db),true); usort($skills, function($item1, $item2){ return $item2['date'] <=> $item1['date']; }); $mostRecent=0; $mostRecentArray=""; foreach($skills as $s){ $curDate = strtotime($s['date']); if($curDate > $mostRecent) { $mostRecent = $curDate; $mostRecentArray=$s; } } if(!empty($mostRecentArray['name'])) $heading=$mostRecentArray['name']; } return $heading; } } else { $this->sgne->triggerError($this->sgne->processError(sgne::COMMON_ERRORS['SQL_QUERY_ERROR'])); } } else { $this->sgne->triggerError(sgne::COMMON_ERRORS['INVALID_PARAM_VALUE']['msg'], sgne::COMMON_ERRORS['INVALID_PARAM_VALUE']['code'],"User ID OR UID"); } } } ?>
Krydos Posted December 7, 2018 Posted December 7, 2018 You're not using php 7.2, you're using 5.6 and that operator isn't available in 5.6 http://sgnetworks.cf/careers4you/config/classes/Careers4You/User/phpinfo.php 1
sagnik Posted December 7, 2018 Author Posted December 7, 2018 Yes, you're right. But, how it can be? I've manually set the PHP version of all domains to PHP 7.2 (ea-php72). Let me confirm that again.
wolstech Posted December 7, 2018 Posted December 7, 2018 I don't see the required directives anywhere in your .htaccess files...it looks like you may have replaced the cPanel generated .htaccess with a custom file, which will in fact cause PHP to switch to 5.6 (the system default). cPanel itself doesn't check the file to determine what you picked, so if you pick a version in cP, then modify or replace the .htaccess file manually afterwards, the version shown in cP and the version actually used can defer. Try changing it to 5.6, then back to 7.2 in cPanel to regenerate the required directives. Note that while it shouldn't, there's a possibility this may break or delete your custom .htaccess file. 1
sagnik Posted December 7, 2018 Author Posted December 7, 2018 Yeah, it worked. But not sure about what happened with the .htaccess file. As I'm using my mobile right now. Thank you very much for helping me.
wolstech Posted December 7, 2018 Posted December 7, 2018 No problem. Let us know if you need anything else 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now