[UPHPU] Calling an object within an object

Jonathan Duncan jonathan at jkdwebmagic.com
Fri Jun 9 17:49:26 MDT 2006


Can anyone help me understand how to call an object function from another 
object within an object?

I have two objects.  In object two I am trying to call a function that I 
defined in object one.  However I am getting "Fatal error: Call to a 
member function on a non-object'" when I try this.  What I have so far I 
pieced together from doing some research on Google.


-----Initialization Script---------------------------
function getClassGuide()
{
     require(ROOT_PATH . '/inc/one.inc.php');
     require(ROOT_PATH . '/inc/two.inc.php');
     $one = new one();
     return new two($one);
}
-----/inc/one.inc.php--------------------------------
class objectOne {

     function makeSelect($var) {
 	// do some stuff
     }
-----/inc/two.inc.php--------------------------------
class objectTwo {

     var $one;

     function objectTwo(&$one) {
         $this->one = $one;
     }

     function getStuff() {
         $Sql = "SELECT stuff FROM table";
         $Result = mysql_query($countiesSql);
         $Array = mysql_fetch_array($Result);
         return $one->makeSelect($Array);
     }
-----Main Script-------------------------------------
$two = getClassTwo();

<?php $two->getStuff(); ?>
-----------------------------------------------------


Thanks,
Jonathan


More information about the UPHPU mailing list