如何从子级返回父函数值

时间:2019-01-29 17:47:46

标签: php laravel

我正在尝试让子函数代表父函数返回。这可能吗?这是我要实现的伪代码:

function editUserProfile(){
    uploadFileToS3($file);
    //Save the rest of the edited profile
}

function uploadFileToS3($file){
    if( fileSize($file) + userStorageUsage > userMaxStorage){
        return redirect()->back()->withErrors(['storage' => 'Storage full']);
    }
    //upload the file
}

编辑:

public function parent()
{
    return $this->child();
}

public function child(){
    if(foo==bar){
        return 'Test';
    }
}

1 个答案:

答案 0 :(得分:1)

只需使用return关键字,例如:

function editUserProfile(){
    return uploadFileToS3($file);
}

或者,如果您想在返回值之前先做些事情,那么:

function editUserProfile(){
    $results = uploadFileToS3($file);
    //Save the rest of the edited profile
    return $results;
}