Page 1 of 1

PHP references to $this

Posted: Tue Jul 14, 2009 1:46 pm
by yacahuma
I want to be able to call the main class from an object of another class. Take a look
What am I missing. Thank you

Code: Select all

 
<?php
class SatClass
{
     var $J;
     var $G;
     var $X;
 
     var $parent;
 
     function __constructor($ref)
     {
         $this->parent = $ref;
     }
 
     function calc()
     {
         return 5 * 5;
     }
 
     function calc5()
     {
         return  $this->parent->getA() * 5;
     }
}
 
class Main
{
    var $A;
    var $B;
    var $C;
 
    var $S1;
 
    function __construct()
    {
        echo "Calling Constructor";
        $this->S1= new SatClass($this);
    }
 
    function getA()
    {
      return $this->A;
    }
}
 
$main = new Main();
$main->A = 5;
echo "DATA=" . $main->getA();
echo "DATA=" . $main->S1->calc();
echo "DATA=" . $main->S1->calc5(); //ERROR Call to a member function getA() on a non-object in 
?>
 
 

Re: PHP references to $this

Posted: Tue Jul 14, 2009 2:18 pm
by VladSun
It's a Pascal error ;)

function __constructor !== function __construct()

Re: PHP references to $this

Posted: Tue Jul 14, 2009 2:56 pm
by yacahuma
Good Lord, I did not see that. Can php just create and alias???