calling class file
Posted: Wed Aug 08, 2007 7:25 am
I have a main class in which i am calling different class files by using :: (scope resolution operator). In the other classes i.e the class files i am using $this-> operator to call the methods of main class as well as methods of other classes, i am able to access all their methods. (without using extend).
For example
main class
in the same way classB and other class are written. I am not extending classes still i am able to access using $this operator
For example
main class
Code: Select all
require_once('classA.php');
require_once('classB.php');
require_once('classC.php');
Class Main {
// methods of main class
function EchoError($error)
{
return "<b>$error</b>";
}
.
.
// methods of other classes called, so that i can call all the methods of any class using one class obj. I am using like a connector to other classes
function callAmethodFromClassA(param1)
{
return ClassA :: callAmethodFromClassA(param1);
}
function callAmethodFromClassB(param1)
{
return ClassB :: callAmethodFromClassB(param1);
}
// so on
}
In ClassA file
require_once('mainclass.php');
require_once('classB.php');
require_once('classC.php');
Class ClassA
{
function FirstMethodOfClassA()
{
$this->EchoError('this is error1');
}
function SecondMethodOfClassA()
{
$this->callAmethodFromClassB(param1);
}
}