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

  • Home
  • SEARCH
  • 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 7958511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:26:03+00:00 2026-06-04T04:26:03+00:00

I’ve just read the page on Expressions in the PHP docs, and right at

  • 0

I’ve just read the page on Expressions in the PHP docs, and right at the top it says:

The simplest yet most accurate way to define an expression is “anything that has a value”.

That simple definition includes all functions and most language constructs, however there a few language constructs that explicitly state they do not return a value.

Here is a list of language constructs that do return a value:

  • empty
  • eval
  • include
  • include_once
  • isset
  • list
  • require
  • require_once
  • print

Here are the interesting few which do not return a value, and therefore are not expressions:

  • die
  • echo
  • exit
  • return
  • unset
  • __halt_compiler

I find die and exit of particular interest, because they can be used as expressions in PHP despite having no return values. The following lines of code all throw a syntax error, as expected:

echo 'Hi' or echo 'Bye';

if(echo('foo'))
     return return(1);

$foo['bar'] = isset($foo['bar']) ? unset($foo['bar']) : 0;

if(unset($foo['bar']))
    __halt_compiler() or die;

However the following PHP code is completely free of syntax errors:

print 'Hi' or print 'Bye';    // Makes sense, print returns a value

if(!die() and exit)           // Wait what's happening here?
    quit(die(exit(quit())));  // die and exit don't have return values (does quit?)

$x = true ? die/2 : 5*exit();
$y = pow(die,7);

isset($_GET['bar']) or die(); // This one is actually pretty commonly used.

function quit(){              
    return exit;
}

I’ve looked through the PHP docs and can’t find any mention of this special treatment of die() and exit(). Do any PHP experts know if this is documented anywhere. Is this intended behaviour, and is the isset($_GET['bar']) or die(); pattern safe to use; could it suddenly break in a future version of PHP?

  • 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-04T04:26:04+00:00Added an answer on June 4, 2026 at 4:26 am

    die and exit (they share the T_EXIT token) fall under the rules for expr_without_variable during the parsing phase, which is why PHP is happy to have them in an expression context without giving a syntax error.

    Do any PHP experts know if this is documented anywhere.

    There is no description of the special treatment in the PHP manual, however the first example on the exit manual page shows it being used as … or exit.

    Is this intended behaviour, and is the isset($_GET['bar']) or die(); pattern safe to use; could it suddenly break in a future version of PHP?

    Yes. Yes. Anything’s possible, however unlikely.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.