Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

php - include with nested round brackets

What does the code below means in PHP7:

(require __DIR__ . '/routes.php')($app);

And how to convert it to non-Uniform syntax?

routes.php content:

use SlimApp;

return function (App $app) {
    // empty
};```
question from:https://stackoverflow.com/questions/65853371/include-with-nested-round-brackets

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

require/include/eval behave like expressions, specifically when the invoked code/file returns something. In this case the return value is used as a function expression. It's equivalent to:

$return = (require "file.php");
${NULL} = $return($app);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...