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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:09:08+00:00 2026-05-16T12:09:08+00:00

A long time ago I used to use or die in my PHP code.

  • 0

A long time ago I used to use “or die” in my PHP code. Especially like this:

$q = mysql_query('......') or die(mysql_error());

Obviously, that’s pretty shameful these days, but the X or Y principle still speaks to me.
So I though I’d try this:

$r = $this->exec($query) or throw new Exception('FAIL');

but that results in a parse error!
What’s the best practice for such statements. It has to look nice as well (obviously!)…

I don’t like

if ( !($r = $this->exec($query)) ) throw new ...

or

$r = $this->exec($query)
if ( !$r ) throw new ....

Any favourites? Discouragements? Best practices? Speed is always nice.

  • 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-16T12:09:09+00:00Added an answer on May 16, 2026 at 12:09 pm

    There’s nothing wrong with the two examples you used, except that you’ve sandwitched them onto one line.

    I’m not sure what you’re looking for, or why you’re finding fault with an if statement – it’s pretty tried and true at this point. That said, you can do something like this to shoe-horn in the or operator, but whoever maintains your code after you’re gone will curse you.

    function throw_ex($what) {
      throw $what;
    }
    
    function fails() {
      return false;
    }
    
    $x = fails() or throw_ex(new exception("failed"));
    

    I don’t see how this gains you anything over the ol’ if statement.

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

Sidebar

Related Questions

I remember that I've seen this effect long time ago on a website. It
I want to compile a code that I have from long time ago using
long time ago I wrote webservice that is still in use. Now I plan
A long time ago I used to program in C for school. I remember
I used the EDT editor on VMS very long time ago. Is there modern
I had this problem a long time ago and recently I got some clues
Either i'm going nuts or nobody likes/liked this feature, but a long time ago
This is one of those things I learned a long time ago and never
I have a problem with Quicktime, that means, QTKit. A long time ago I
I was revisting some code I wrote a long time ago, and decided to

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.