Aureole Posted February 5, 2008 Share Posted February 5, 2008 Ok I have a problem, I'm not going to post all of the class(es)... just the relevant part(s)... <?php class equinox { /** * Variables from conf.php * @var [array] */ var $vars; function init_db() { require_once( 'class_database.' . $this->vars['php_ext'] ); $this->database = new database; $this->database->equinox =& $this; $this->database->connect(); } function dump_vars( $dump_db_vars = 0 ) { foreach($this->vars as $key => $val) { if( $dump_db_vars == 0 ) { if ( substr( $key, 0, 2 ) !== 'db' ) { echo( "<strong>$key: </strong>$val<br>\n" ); } } else { echo( "<strong>$key: </strong>$val<br>\n" ); } } } } ?> Then the database class is as follows... <?php class database { function connect() { print_r( $this->equinox->dump_vars() ); $db_connect = mysql_connect( $this->equinox['db_host'], $this->equinox['db_user'], $this->equinox['db_pass'] ); echo( $db_connect ) ? 'Success' : mysql_error(); } } ?> When I do the print_r(), it does it twice for some reason... I think maybe I've created another instance of the equinox class within the database class... that's not what I wanted to do, I just want it to be passed along so I can use the $equinox->vars stuff as that contains the database information... I don't have PHP 5, so keep that in mind... my PHP version is in my signature. Link to comment https://forums.phpfreaks.com/topic/89523-solved-ok-now-im-confused/ Share on other sites More sharing options...
trq Posted February 5, 2008 Share Posted February 5, 2008 Your parsing print_r a function which already echo's the data your trying to print. Try simply... $this->equinox->dump_vars(); instead of.... print_r( $this->equinox->dump_vars() ); Link to comment https://forums.phpfreaks.com/topic/89523-solved-ok-now-im-confused/#findComment-458635 Share on other sites More sharing options...
Aureole Posted February 6, 2008 Author Share Posted February 6, 2008 That's what you get for coding non-stop for too long... thanks, though after I removed the print_r() it was still doing it twice. But now I've had a good sleep, I found out why straight away. Link to comment https://forums.phpfreaks.com/topic/89523-solved-ok-now-im-confused/#findComment-459576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.