Hi - just getting started with classes. Two things I'd like to be able to do, but not sure how.
- Getting global variables into my class
At the beginning of a class I must define my variables:
var $foo [ = "bar"];
Is there a way to get variables from outside the class into the class? I know I can do them in a class function with the keyword "global", but that doesn't seem to work outside functions. It that case "global" just seems to break the class completely.
I suppose one way would be to do something like this:
class Monkey {
var $foo;
function PullInFoo() {
global $foo;
$this->foo = $foo;
}
}
Is that as neat as I can get, or is there a slicker way to do this?
- External functions. Is there any way to call a function outside a class from within a class? I have a function that reformats emails & such, and I'd like to apply it to certain text within a function.
Thanks!
Classes are cool.