Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6051423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:49:08+00:00 2026-05-23T07:49:08+00:00

Is it possible to have return statements inside an included file that is inside

  • 0

Is it possible to have return statements inside an included file that is inside a function in PHP?

I am looking to do this as I have lots of functions in separate files and they all have a large chunk of shared code at the top.

As in
function sync() {
  include_once file.php;
  echo "Test";
}

file.php:

...
return "Something";

At the moment the return something appears to break out of the include_once and not the sync function, is it possible for the included file’s return to break out?

Sorry for the slightly odly worked question, hope I made it make sense.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:49:09+00:00Added an answer on May 23, 2026 at 7:49 am

    You can return data from included file into calling file via return statement.

    include.php

    return array("code" => "007", "name => "James Bond");
    

    file.php

    $result = include_once "include.php";
    var_dump("result);
    

    But you cannot call return $something; and have it as return statement within calling script. return works only within current scope.

    EDIT:

    I am looking to do this as I have lots
    of functions in separate files and
    they all have a large chunk of shared
    code at the top.

    In this case why don’t you put this “shared code” into separate functions instead — that will do the job nicely as one of the purposes of having functions is to reuse your code in different places without writing it again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Should a function have only one return statement? This is what I
I was surprised recently to find that it's possible to have a return statement
I have four IF statements, is it possible to rewrite this into a neater
Possible Duplicate: substring and the indexOf method I have this problem that I'm going
I have a file with various 'return BBQ;' statements. I'd like to change them
Is it possible to have the router return an error code (or an entire
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Is it possible that a multi-statement UDF return a User Defined Table Type, instead
I have tried this in multiple ways: if-then-else, guards, case statements but I never
In Python, is it possible to have multiple except statements for one try statement?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.