passing parameters to php include/require construct

前端 未结 4 630
隐瞒了意图╮
隐瞒了意图╮ 2021-02-12 11:01

I\'ve read quite a few posts that are very similar to the question I\'m about to ask, but I just wanted to be sure that there wasn\'t a more sophisticated way to do this. Any f

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 11:12

    You could have the required file return an anonymous function, and then call it immediately after.

    //required.php
    
    $test = function($param)
    {
        //do stuff
    }
    
    return $test
    
    //main.php
    $testing = require 'required.php';
    $testing($arg);
    

提交回复
热议问题