But is there a default function that php calls when displaying any object that I can override?
class myObject {
private $value = 45;
// .... other variables
// Override default function that gets called by php when outputting
public function __display()
return $this->value;
}
}
$obj = new myObject();
echo $obj; // Will call __display();
Main Topics
Browse All Topics





by: hieloPosted on 2008-02-19 at 07:02:56ID: 20928918
>>How can I control what is echoed?
You need public properties or public methods that return the values of the private properties:
class myObject {
private $value = 45;
// .... other variables
function getData()
return $this->value;
}
}
$obj = new myObject();
echo $obj->getData();