Jump to content

Undefined Autoloaded Class Properties


Yohanne

Recommended Posts

Hi coders,

 

i have 2 files where one file is auto loaded into another one file. now i get lost since before i can do this like below but i dont know why i get this error now  Undefined variable: new_varname in 

 

 

please help 

 

 

ClassVar.php

class ClassVar
{
	function __construct()
	{
		$newConnect = new connection();
	}
					
	public $VarConn;
	public $VarmysqlCon;
				
				
	public function set_VarConn($VarConn)
	{
		$this->VarConn = $VarConn;
	}

	function get_VarConn()
	{
	         return $this->VarConn;
	}
					
			
         public function set_VarsqlConn($VarmysqlCon)
	{
		$this->VarmysqlCon = $VarmysqlCon;
	}
	function get_VarsqlConn()
	{
		return $this->VarmysqlCon;
	} 
					
}
function __autoload($classname)
{
$filename = "./../". $classname .".php";  include_once($filename);
}

class CheckDetail
 {
function __construct()
	{
		$new_varname = new ClassVar();
	}
public function table_pro_user()
{

$new_varname->set_VarsqlConn("SELECT * FROM  user WHERE (x = 'a') && (z = 'a')");
$new_varname->get_VarConn = mysql_query($new_varname->get_VarsqlConn());
					
if(mysql_num_rows($new_varname->get_VarConn) == 1)
	{
		echo 'wow';
	}
else
	{
		echo 'ngik';
	}
}
}
	$dfdf = new CheckDetail();
	$dfdf->table_pro_user();
Link to comment
https://forums.phpfreaks.com/topic/280301-undefined-autoloaded-class-properties/
Share on other sites

class variables are referenced inside their class using $this->variable_name, like you are doing in the class ClassVar. $new_varname is just a local variable that only exists inside the __construct() function. it is not a class variable (likewise for the $newConnect variable in the first class.)

Ok Thanks, but same problem even i put that tag.  i get to change something, i put " $new_varname = new ClassVar();" inside the public method "table_pro_user". its works he get the data connection but "get_VarConn" and "get_VarsqlConn" he did not read? why?

 

any idea? 

function __autoload($classname)
{
$filename = "./../". $classname .".php";  include_once($filename);
}

class CheckDetail
 {
public function table_pro_user()
{
   
        $new_varname = new ClassVar();

$new_varname->set_VarsqlConn("SELECT * FROM  user WHERE (x = 'a') && (z = 'a')");
$new_varname->get_VarConn = mysql_query($new_varname->get_VarsqlConn());
					
if(mysql_num_rows($new_varname->get_VarConn) == 1)
	{
		echo 'wow';
	}
else
	{
		echo 'ngik';
	}
}
}
	$dfdf = new CheckDetail();
	$dfdf->table_pro_user();

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.