I'm currently working on a PHP component: "Filesystem handler". I've run into a problem where I want to call one exact method in both dynamic and static ways.
I've ended up with this solution. Could you please give me a feedback ? I want to know, if there is a better or a simpler way to achieve the same result.
<?php
class File {
protected $file;
public function __construct($file) {
$this->file = $file;
}
protected static function exists($arg) {
var_dump($arg);
}
public function __call($method, $parameters = null) {
if($method == 'exists') {
return call_user_func_array(array($this, 'exists'), array(array($this->file)));
}
}
public static function __callStatic($method, $parameters) {
if($method == 'exists') {
return call_user_func(__CLASS__.'::exists', $parameters);
}
}
}
$file = new File('dynamic');
$file->exists();
File::exists('static');