I have an interface like this:
interface General {
public function getFile($file);
public function searchFile($to_search);
}
I have a class, like so:
class Parent implements General {
public function getFile($file) {
$loaded = file($file);
}
public function searchFile($to_search) {
$contents = $this->getFile(); // doesn't work because I need the $file from get_file()!
// searches file
// returns found items as collection
}
}
Then in the code, I can do something like....
$file = "example.txt";
$in = new Parent();
$in->getFile($file)
$items = $in->searchFile('text to search');
foreach($item as $item) {
print $item->getStuff();
}
All the examples I have seen to reference another function within a class don't take an argument.
How do I reference the $file from getFile($file) so that I can load the file and start searching away? I want to implement it through the interface, so don't bother changing the interface.
$file. Where that value comes from is entirely up to you.