public function getString($propName, $default = '')
{
// does this property exist at all?
if (!isset($this->{$propName})) {
// no, so return the default
return $default;
}
// is this property something that can be auto-converted to a
// string reliably?
if (is_string($this->{$propName}) || is_int($this->{$propName}) || is_double($this->{$propName})) {
// yes
return (string) $this->{$propName};
}
// starting to clutch at straws now
// a boolean, perhaps?
if (is_bool($this->{$propName})) {
if ($this->{$propName}) {
return 'TRUE';
}
return 'FALSE';
}
// is it an object that can convert itself to a string?
if (is_object($this->{$propName})) {
$refObj = new ReflectionObject($this->{$propName});
if ($refObj->hasMethod('__toString')) {
return (string) $this->{$propName};
}
// sadly, the object cannot convert itself to a string
return $default;
}
// add any other conversions in here
// okay, we give up
return $default;
}