这是我的代码:
public function call_with_attempts($class_obj, $method_name,array $params = [], $attempts = 5) {
while ($attempts-- > 0) {
try {
if (call_user_func(array($class_obj, $method_name), $params)['result_code'] == '01') {
// log success
return $class_obj->$method_name();
}
throw new Exception("failed");
} catch (Exception $e) {
trigger_error($e->getMessage());
// log the error
}
}
}
我称之为:
$url = 'www.example.com';
$obj = new Profile($url);
all_with_attempts($obj, 'mymethod');
这里是Profile
课程:
class profile {
public $url;
public function __construct( $passed_url )
{
$this->url = $passed_url;
}
public function mymethod(){
// do stuff
}
}
我的任何代码(当我调用此函数all_with_attempts($obj, 'mymethod');
时)。抛出此错误:
在{/ path}中调用的App \ classes \ Profile :: __ construct()缺少参数1
如你所知,这个错误^表示将再次创建Profile
类...那不是我想要的。我想使用$obj
。我怎么能这样做?