How to force a variable to be a custom object?
| From: | Alex Gemmell | Date: | Fri, 02 Sep 2005 12:31:43 +0000 |
| Subject: | How to force a variable to be a custom object? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-221754@lists.php.net to get a copy of this message | ||
Hi all,
Just a quickie today: I was wondering if I can declare a Class variable as a certain type of object. I'm using PHP 4 by the way.
For example, if my class looks like this:
class myClass {
var $object;
function someFunction() {
// code, code, code ....
}
}
Is there anyway I can limit the variable "$object" to be of a particular Class of object that I have made. Something like:
class myClass {
var $object *type=myOtherClass*;
function someFunction() {
// code, code, code ....
}
}
Yes, yes, I know "*type=myOtherClass*" isn't PHP code, but do you see what I'm getting at? How would I achieve this? Is it even possible?
And would I then also have to include/require the path to the "myOtherClass" definition script in the myClass definition?
e.g.
class myClass {
*require_once('path/to/myOtherClass.php');*
var $object *type=myOtherClass*;
function someFunction() {
// code, code, code ....
}
}
Any ideas folks?
All the best,
Alex