Php 如何从子函数返回父函数值

Php 如何从子函数返回父函数值,php,laravel,Php,Laravel,我试图让一个子函数代表父函数返回。这可能吗?下面是我试图实现的伪代码: function editUserProfile(){ uploadFileToS3($file); //Save the rest of the edited profile } function uploadFileToS3($file){ if( fileSize($file) + userStorageUsage > userMaxStorage){ return re

我试图让一个子函数代表父函数返回。这可能吗?下面是我试图实现的伪代码:

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
}
编辑:


只需使用
return
关键字,如:

function editUserProfile(){
    return uploadFileToS3($file);
}
或者,如果要在返回值之前执行某些操作,则:

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

我建议尝试提供更多的代码。至少对我来说,我不认为我能从那个片段中帮助你。非常感谢。太好了。如果不在父函数中使用if,是否可以忽略返回?@CharlvanStaden您可以在子函数中使用if。如果我的帖子回答了你的问题,你可以考虑接受它作为正确的答案。请参阅我的编辑。这就是你的想法吗?父函数仍然始终返回null。@CharlvanStaden这意味着if条件的计算结果为false。
function editUserProfile(){
    $results = uploadFileToS3($file);
    //Save the rest of the edited profile
    return $results;
}