Jump to content

Undefined Autoloaded Class Properties


Yohanne
Go to solution Solved by 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
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.)

Link to comment
Share on other sites

  • Solution

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();
Link to comment
Share on other sites

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.