08-26-2009, 02:53 PM
|
#4 (permalink)
|
|
The Acquainted
Join Date: May 2009
Posts: 178
Thanks: 9
|
Here's an example:
My class:
PHP Code:
class SimpleClass
{
public function __contruct($variable1,$variable2) {
do some stuff with variables 1 and 2;
}
}
My client code:
PHP Code:
$newobject = New SimpleClass($variable1);
This errors and the script stops executing because the class hasnt received the 2 variables required to instantiate the object. I have this option (which i dont want to do):
PHP Code:
if ((isset(variable1)) && (isset($variable2))) {
$newobject = New SimpleClass($variable);
}
Is there a way I could handle this more elegantly? i.e. i want the class to be robust enough to handle idiots passing in junk data. I assume that is the point of object orientation.
|
|
|
|