Yohanne Posted July 19, 2013 Share Posted July 19, 2013 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(); Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 19, 2013 Share Posted July 19, 2013 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.) Quote Link to comment Share on other sites More sharing options...
Yohanne Posted July 20, 2013 Author Share Posted July 20, 2013 Okay Thanks, but there is any other possible way to use class below, inside the class of "CheckDetail"? $new_varname = new ClassVar(); Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 20, 2013 Share Posted July 20, 2013 Okay Thanks, but there is any other possible way to use class below, inside the class of "CheckDetail"? $this->new_varname = new ClassVar(); And everywhere in that class you will use $this->new_varname. Quote Link to comment Share on other sites More sharing options...
Solution Yohanne Posted July 20, 2013 Author Solution Share Posted July 20, 2013 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(); Quote Link to comment Share on other sites More sharing options...
trq Posted July 20, 2013 Share Posted July 20, 2013 The explanation of your problem lakes clarity. What exactly is your issue? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.