so i am pretty new to OOP PHP. i am trying to get a feel for it, i am makeing a simple class with 2 functions
one for speed of the car(he try's te see if the speed is a good value)
and one for color of the car(check if the color is vailid)
the error i got:
Catchable fatal error: Object of class Auto could not be converted to string in E:\Site peter+usbweboot\stage\oef\Auto.php on line 44
here is my code:
<?php
class Auto {
public $mKleur = "";
public $mSpeed = "";
public function speed ($var){
if(is_numeric($var)){
if($var < 0 OR $var == 0)
{
$this->mSpeed = ("$var kmpu rijd die waggie niet eens?!");
}
elseif ($var > 206 OR $var == 206)
{
$$this->mSpeed = ("$var kmpu haalt de auto niet!");
}
elseif($var > 0 AND $var < 206)
{
$$this->mSpeed = ("de auto reed met $var kmpu langs!");
}
}
else
{
$$this->mSpeed = ( " $var dat niet eens een getal....");
}
}
private $sKleur = "";
public function __set( $sAttribuut, $sValue ){
switch( $sAttribuut ){
case 'sKleur':
$aValideKleuren = array('groen', 'rood', 'blauw', 'paars', 'geel', 'wit', 'zwart','grijs','oranje' );
if( !in_array( strtolower( $sValue ), $aValideKleuren ) ){
$$this->mKleur = ("Kleur niet bekend: $sValue");
}
else{
$$this->mKleur = ("kleur is bekent namelijk: $sValue");
}
$this->sKleur = $sValue;
break;
default:
break;
}
}
public function __get( $sAttribuut ){
if( isset( $this->$sAttribuut ) ){
return $this->$sAttribuut;
}
}
public function kk()
{
$message = array('gSpeed' => $this->mSpeed, 'gKleur' => $this->mKleur);
return($message);
}
}
?>
it does work if i use echo but i cant get it te return the value's
anyone know why?