Jump to content


Photo

[Answered] Spaceship (<=>) operator not working on PHP7.2 (ea-php72)


  • Please log in to reply
7 replies to this topic

#1 sagnik

sagnik

    Rank V Member

  • Members
  • PipPipPipPipPip
  • 386 posts
  • Gender:Male
  • Location:Durgapur, West Bengal, India
  • Interests:Internet, Computer, Coding, Website Designing

Posted 07 December 2018 - 10:57 AM

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");
		}
	}
}
?>

- By Sagnik

#2 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,162 posts
  • Gender:Male

Posted 07 December 2018 - 06:03 PM

You're not using php 7.2, you're using 5.6 and that operator isn't available in 5.6 http://sgnetworks.cf...ser/phpinfo.php

#3 sagnik

sagnik

    Rank V Member

  • Members
  • PipPipPipPipPip
  • 386 posts
  • Gender:Male
  • Location:Durgapur, West Bengal, India
  • Interests:Internet, Computer, Coding, Website Designing

Posted 07 December 2018 - 06:08 PM

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.
- By Sagnik

#4 sagnik

sagnik

    Rank V Member

  • Members
  • PipPipPipPipPip
  • 386 posts
  • Gender:Male
  • Location:Durgapur, West Bengal, India
  • Interests:Internet, Computer, Coding, Website Designing

Posted 07 December 2018 - 06:20 PM

http://imgur.com/a/8flhLCe
- By Sagnik

#5 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 9,358 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 07 December 2018 - 06:27 PM

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.


Please do not PM me for support. Posting on our forums lets all of us learn.

Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#6 sagnik

sagnik

    Rank V Member

  • Members
  • PipPipPipPipPip
  • 386 posts
  • Gender:Male
  • Location:Durgapur, West Bengal, India
  • Interests:Internet, Computer, Coding, Website Designing

Posted 07 December 2018 - 06:39 PM

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.
- By Sagnik

#7 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 9,358 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 07 December 2018 - 06:43 PM

No problem. Let us know if you need anything else :)


Please do not PM me for support. Posting on our forums lets all of us learn.

Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#8 Luigi123

Luigi123

    Rank X Member

  • Moderators
  • 1,187 posts
  • Gender:Male
  • Location:Winnipeg, Manitoba, Canada

Posted 07 December 2018 - 08:52 PM

Moved to Customer Service.

server_load_s.gifserver_load_j.gifserver_load_t.gif
server_uptime_s.gifserver_uptime_j.gifserver_uptime_t.gif

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users