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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:23:23+00:00 2026-06-12T19:23:23+00:00

As stated here php.net/return , there is an option to stop executing include with

  • 0

As stated here php.net/return, there is an option to stop executing include with ‘return’ statement.

Who can tell me why this works as stated below

// test1.php

include 'test2.php';
var_dump(class_exists('TestClass_ShouldntBeDefined'));

// test2.php

return;
class TestClass_ShouldntBeDefined { }

// run

$ php -f test1.php
bool(true)

Why this is true?

When test2.php is changed to any other form of code execute (if(true) { ... })

return;
{
    class TestClass_ShouldntBeDefined { }
}

then it works as expected

$ php -f test1.php
bool(false)

PHP version

$ php -v
PHP 5.4.7 (cli) (built: Sep 13 2012 04:20:14) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
  • 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-06-12T19:23:25+00:00Added an answer on June 12, 2026 at 7:23 pm

    Return ends execution, but does not stop the include.

    In the first case, the file is included, and execution stops after the return and control is given back to test1.php. But the class is included, and therefore class_exists returns true. So case 1 works as expected.

    In the second case, by using the curly braces, the class definition becomes part of the execution. The return ends execution of the include, before the class is defined.

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

Sidebar

Related Questions

Im using the Google pagerank checking script found here: http://www.off-soft.net/en/develop/php/prcheck.html I've noticed however that
I've successfully installed this jQuery-based signup form here: http://net.tutsplus.com/tutorials/javascript-ajax/building-a-sleek-ajax-signup-form/ But when I applied it
My question is rather simple, here is the context: http://php.net/manual/en/language.oop5.magic.php Magic Methods The function
In php reading from here http://docs.php.net/manual/en/migration54.new-features.php It says, Class member access on instantiation has
The following example is taken from: http://php.net/manual/en/function.curl-multi-close.php#example-3540 This example will create two cURL handles,
So what I'm looking for here is something like PHP's print_r function. This is
I have started using PDO in php for the first time. Here is my
This started over here when I was getting Class 'Classname_model' not found . I
I heard that ASP.net MVC does not maintain View State.So,here is my question I
Here are the ways the Eclipse documentation states you can navigate the Content Assist

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.