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 692249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:37:52+00:00 2026-05-14T02:37:52+00:00

How can I tell if return() was called from within the included file. The

  • 0

How can I tell if return() was called from within the included file. The problem is that include() returns ‘int 1’, even if return() wasn’t called. Here is an example…

included_file_1.php

<?php

return 1;

included_file_2.php

<?php

echo 'no return here, meep';

main.php

<?php

$ret = include('included_file_1.php');

// This file DID return a value, int 1, but include() returns this value even if return() wasn't called in the included file.
if ($ret === 1)
{
    echo 'file did not return anything';
}

var_dump($ret);

$ret = include('included_file_2.php');

// The included file DID NOT return a value, but include() returns 'int 1'
if ($ret === 1)
{
    echo 'file did not return anything';
}

var_dump($ret);

Edit: As a temporary solution, I’m catching the output from include() (from echo/print statements). If any output was produced, I ignore the return value from include().

Not pretty, but it provides the functionality I need in my web app/framework.

  • 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-14T02:37:53+00:00Added an answer on May 14, 2026 at 2:37 am

    Good question. Looking at the examples in the manual, I guess you can’t.

    The best workaround idea that comes to mind is to make all your includes in your project not return naked values, but an array containing the return value (return array(1);).

    Everything else that comes to mind (mine at least) involves defining some constants or variables to flag whether you’re in an include or not. Nothing elegant.

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

Sidebar

Related Questions

Can somebody tell me why compiler thinks that break is necessary after yield return
int main() { double i=4; printf(%d,i); return 0; } Can anybody tell me why
Can anyone pls tell me that, why I can't use normal C++ classes within
Can anyone tell me why this isn't working? It always returns false . $str
so from what i can tell, you have to specify artifacts and working directory
Often I will send debugging info to my log file from within Java, and
I have an INT fields called TradeNo that may contain NULL value. The requirement
Can you tell me the exact difference between return self::__construct() and return new self()
Anyone can tell me which one is better (JAXB or Apache XMLBeans) taking in
Anyone can tell me what I'm doing wrong? I am creating a simple system

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.