I am trying to convert some old library functions into a class. (i'm trying to force myself to learn OOP)
The Class:calling the class produces the error:PHP Code:class timestamp {
protected $input;
protected $aDate;
protected $datetime;
public function __construct($input) {
$this->input = $input;
}
public function stamp() {
if(strpos($this->input, "-") && !strpos($this->input, ":")) {
$aDate = explode("-",$this->input);
$datetime = mktime(0, 0, 0, $aDate[1], $aDate[2], $aDate[0]);
}
elseif(strpos($this->input, ":") && !strpos($this->input, "-")) {
$aTime = explode(":",$this->input);
$datetime = mktime($aTime[0], $aTime[1], $aTime[2], 1, 1, 2007);
}
else {
$datetime = explode(" ",$this->input);
$aDate = explode("-",$datetime[0]);
$aTime = explode(":",$datetime[1]);
$datetime = mktime($aTime[0], $aTime[1], $aTime[2], $aDate[1], $aDate[2], $aDate[0]);
}
return $datetime;
}
}
I've worked out its the strpos() function that's causing the error and I understand that you can use __toString() to convert an object to a string but am not sure how to implement it in this set-up.Catchable fatal error: Object of class timestamp could not be converted to string
Any help much appreciated.




Bookmarks