vars from parent class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,

1. Folks I have a parent class cMySQL the handles basic mysql queries
and connection ...

2. I have a child class cGetMenu which uses methods of parent class for
accessing mysql
3. in cGetMenu class the constructor checks if the given menu table is
of appropriate structure:

$fields = mysql_list_fields($this->MYSQL_DATABASE, $this->menu_table,
$this->connection);
		$columns = mysql_num_fields($fields);
		for ($i=0; $i<$columns; $i++):
		    $table_columns[] = mysql_field_name($fields, $i);
		endfor;

4. $this->MYSQL_DATABASE and $this->connection are the vars from
existing instance of parent cMySQL class

QUESTION: how do I get these vars from existing instant of parent class
MySQL and pass them to child?


My solution is by getting vars by get_object_vars() 

$sql = new cMySQL();
	$sql->MYSQL_PASSWORD="blablabla";
	$sql->MYSQL_USERNAME="blabla";
	$sql->MYSQL_DATABASE="dev";
	$sql->MYSQL_SERVER="localhost";
	$sql->connect();

$sql_vars = get_object_vars($sql);
$get_menu = new cGetMenu("menu_$lg", $sql_vars);

and then giving it to constructor of child class as an array and
defining them again

function cGetMenu($menu_table, $sql_vars){ 
// this function checks whether there is a menu table or required
structure
// $sql_vars are variables from existing instant of parent class cMySQL
		$this->menu_table = $menu_table;
		$this->MYSQL_DATABASE = $sql_vars['MYSQL_DATABASE'];
		$this->connection = $sql_vars['connection'];
.....


Is there any other way how to solve this?

Thanks, thanks, thanks

Adrian 






PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux