Possible Duplicate:
PHP method chaining?
I occasionally see some php applications use classes like that:
$Obj = new Obj();
$Obj->selectFile('datafile.ext')->getDATA();
The example above gets the contents of the selected file then returns them ( just an example );
Well, before i decided to ask you how can I do this, I tried this:
class Someclass {
public function selectFile( $filename ) {
$callAclass = new AnotherClass( $filename );
return $callAclass;
}
// Other functions ...
}
class AnotherClass {
protected $file_name;
public function __construct ( $filename ) { $this->file_name = $filename; }
public function getDATA ( ) {
$data = file_get_contents( $this->file_name );
return $data;
}
// funcs , funcs, funcs ....
}
Is that the right way to accomplish this task? And please tell me what these classes are called.