Click to See Complete Forum and Search --> : Class Help


metack
10-03-2003, 10:20 AM
If i were to call another class from inside a class would i have to name that new object as an object in the first class? Or could I make the object global inside of the function i call it in or the class?

Khalid Ali
10-03-2003, 12:18 PM
logically, when you declare a class object in a function,its scope is limited to that function and when you declare it in a class out side of any other function its scope is global to all the functions in that class.Its upto you and the logic you may have for the program to determine where you want to declare any or all classes.(I hope thats what you were asking..:D )

metack
10-03-2003, 12:58 PM
Let me know if this assumtion is correct. SO in order to call an object (declared outside of all classes and functions) from another class I must make that object global inside of that class or I must create a new object inside of the new class.


My issue is that I am usng a database class. I create the database object in the global scape (outside of all functions and classes) but I want to use that database object inside of my user-management class.

fyrestrtr
10-05-2003, 01:29 PM
You can pass the object by reference and have the same effect (instead of going through all of the global include hoops).

If you don't need to use a particular object, you can just reference a class's members (statically), by using the scope resolution operator( :: ), thusly :



class a {
var $foo;
function print() { echo "Hello World"; }
function setF($x) { $this->foo = $x; }
function getF() { return $this->foo; }
}

$obj = new a();
$obj->print();
$obj->setF(4);
echo $obj->getF();

a::print();