Jump to content

Recommended Posts

Hi,

 

I'm getting this error when running a script

 

Fatal error: Using $this when not in object context in /var/www/vhosts/********/subdomains/test/httpdocs/include/common.php on line 11

 

line 11, 12 & 13  are  here:

 

$this->min_pass_length=8;

$this->max_pass_length=12;

$this->chars='abcdefghijklmnopqrstuvwxyz0123456789';

 

any advise wouldbe great please!

 

Link to comment
https://forums.phpfreaks.com/topic/140026-help-with-this-error-please/
Share on other sites

Hi,

 

I'm getting this error when running a script

 

Fatal error: Using $this when not in object context in /var/www/vhosts/********/subdomains/test/httpdocs/include/common.php on line 11

 

line 11, 12 & 13  are  here:

 

$this->min_pass_length=8;

$this->max_pass_length=12;

$this->chars='abcdefghijklmnopqrstuvwxyz0123456789';

 

any advise wouldbe great please!

 

 

PHP errors tend to happen on the lines before the one specified by the error itself.  Your best bet is to post everything relevant to the process (I'm guessing an object's constructor) so we can see what's happening.

<?
session_start();
include("config.php");

$att_path = "uploads/";
$paypal_item_number = $sitename;
$mainipn = $siteurl."/ipn.php";
$paypal_ipn = $siteurl."/site_ipn.php";
$paypal_cancel_return = $siteurl."/cancel.php";
$paypal_return = $siteurl."/thanks.php";
$this->min_pass_length=8;
$this->max_pass_length=12;
$this->chars='abcdefghijklmnopqrstuvwxyz0123456789';
$logfile = "logfile.txt";
$postmode = 1;
$invalidcode = "<table bgcolor=#ffffff cellpadding=4 width=170><tr><td align=center><font size=2><b>Invalid Button Code!</b><p>Run Your Own PayPal Donation Campaigns at <a href=$siteurl/join.php>$sitename</a></font></table>";
$table1 = "<TABLE class=design bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#C0C0C0' STYLE='border-collapse: collapse'>";
$table2 = "<TABLE class=design bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100%'>";
$table3 = "<TABLE class=design bgColor=#ffffff cellPadding=3 cellSpacing=0 width=100% border='1' BORDERCOLOR='#C0C0C0' STYLE='border-collapse: collapse'>";

@mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server: " . mysql_error());
@mysql_select_db($dbName) or die("Couldn't connect to database: " . mysql_error());

function errform($msg, $var = ''){ 
	global $posterr, $_POST; 
	$posterr = 1; 
	echo "<div style='color: #FF0000;'>$msg</div>";
	if ($var) $_POST[$var] = '';
}

function getCount($cat){
	list($cnt) = mysql_fetch_array( mysql_query("SELECT COUNT(*) AS cnt FROM users WHERE cat='$cat'") );
	return $cnt;
}

function buildDateBox($type,$name,$sel){
	$months = Array(
			"1"=>"January",
			"2"=>"February",
			"3"=>"March",
			"4"=>"April",
			"5"=>"May",
			"6"=>"June",
			"7"=>"July",
			"8"=>"August",
			"9"=>"September",
			"10"=>"October",
			"11"=>"November",
			"12"=>"December");
?>
	<SELECT NAME="<?=$name?>">
<?
	switch($type){
		case "d":
			echo "<option value=''>-----";
			for($i = 1;$i <= 31;$i++){
				$arlist[$i] = $i;
			}
			break;
		case "y":
			echo "<option value=''>Optional";
			$year = (date("Y")+1);
			for($i = $year;$i >= 1900;$i--){
				$arlist[$i] = $i;
			}
			break;
		case "m":
		default:
			echo "<option value=''>-----";
			$arlist = $months;
			break;
	}
	while( list($i,$val) = each($arlist) ){
		if($sel == $i){
			echo "<OPTION VALUE=\"$i\" SELECTED>$val</OPTION>\n"; 
		}else{
			echo "<OPTION VALUE=\"$i\">$val</OPTION>\n"; 
		}
	}
?>

	</select>
<?
}

function edulevel($name,$sel){
	global $edu_level;
	reset($edu_level);
	echo "<select name='$name'>";
	while( list($i,$val) = each($edu_level) ){
		if($sel == $i){
			echo "<OPTION VALUE=\"$i\" SELECTED>$val</OPTION>\n"; 
		}else{
			echo "<OPTION VALUE=\"$i\">$val</OPTION>\n"; 
		}
	}
	echo "</select>";
}

function myround($amt,$dec="3"){
	ob_start();
	if($dec == 2){
		printf("%6.2f",$amt);
	}else{
		printf("%6.3f",$amt);
	}
	$amount = ob_get_contents();
	ob_end_clean(); 
	$amount = str_replace(" ","",$amount);
	return $amount;
}

class fptime{
	function fptime(){
		return 1;
	}

	function mytime($stamp="",$format="m/d/Y"){
		return date( $format,($stamp ? $stamp : time()) );
	}

	function stamp($mm,$dd,$yy,$hh=0,$min=0,$sec=0){
		return mktime($hh,$min,$sec,$mm,$dd,$yy);
	}

	function subhours($interval,$mm,$dd,$yy,$hh,$m,$s){
		return $this->stamp( $mm,$dd,$yy,($hh-$interval),$m,$s );
	}

	function addhours($interval,$mm,$dd,$yy,$hh,$m,$s){
		return $this->stamp( $mm,$dd,$yy,($hh+$interval),$m,$s );
	}

	function subdays($interval,$mm,$dd,$yy){
		return $this->stamp($mm,($dd-$interval),$yy);
	}

	function adddays($interval,$mm,$dd,$yy,$hh=0,$min=0,$sec=0){
		return $this->stamp($mm,($dd+$interval),$yy,$hh,$min,$sec);
	}

	function submonths($interval,$mm,$dd,$yy){
		return $this->stamp( ($mm-$interval),$dd,$yy );
	}

	function addmonths($interval,$mm,$dd,$yy){
		return $this->stamp( ($mm+$interval),$dd,$yy );
	}

	function subyears($interval,$mm,$dd,$yy){
		return $this->stamp( $mm,$dd,($yy-$interval) );
	}

	function addyears($interval,$mm,$dd,$yy){
		return $this->stamp( $mm,$dd,($yy+$interval) );
	}

	function DateDiff ($interval, $date1,$date2) {
		// get the number of seconds between the two dates
		$timedifference =  $date2 - $date1;
		switch ($interval) {
			case "w":
				$retval = $timedifference/604800;
				$retval = floor($retval);
				break;
			case "d":
				$retval = $timedifference/86400;
				$retval = floor($retval);
				break;
			case "h":
				$retval = $timedifference/3600;
				$retval = floor($retval);
				break;
			case "n":
				$retval = $timedifference/60;
				$retval = floor($retval);
				break;
			case "s":
				$retval  = floor($timedifference);
				break;
		}
		return $retval;
	}

	function dateNow($format="%Y%m%d"){
		return(strftime($format,time()));
	}

	function dateToday(){
		$ndate = time();
		return( $ndate );
	}

	function daysInMonth($month="",$year=""){
		if(empty($year)) {
			$year = $this->dateNow("%Y");
		}
		if(empty($month)) {
			$month = $this->dateNow("%m");
		}
		if($month == 2) {
			if($this->isLeapYear($year)) {
				return 29;
			} else {
				return 28;
			}
		} elseif($month == 4 or $month == 6 or $month == 9 or $month == 11) {
			return 30;
		} else {
			return 31;
		}
	}

	function isLeapYear($year=""){
		if(empty($year)) {
			$year = $this->dateNow("%Y");
		}
		if(strlen($year) != 4) {
			return false;
		}
		if(preg_match("/\D/",$year)) {
			return false;
		}
		return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
	}
}
?>

Why are you using $this, you have not defined an object period, and even if you did you would need to access the data in it with $object

 

I would suggest removing the this-> part and just making min and max variable names, or figure out what the object you are to be referencing should be and use that.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.