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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:04:20+00:00 2026-05-28T19:04:20+00:00

I’m new to php and I am a bit confused by the fact that

  • 0

I’m new to php and I am a bit confused by the fact that there seems to be no error object communication from a method to its caller.

These two are the ways I learn to use:

  1. If a method should not info the caller of the error it just triggers an error an if this is not E_USER_ERROR it just can return FALSE to tell the caller something went wrong.

  2. On the other way if a method needs to send back some error info to the caller an exception should be raised.

Coming from COCOA I have learn to use exceptions on extraordinary conditions (non recoverable errors due to programmer mistakes). In any other case just pass an error object to the caller.

  • Is the philosify different in PHP?
  • Are exceptions the standar mechanism to send back error data to the caller?
  • Should I avoid programming my own error objects and pass then as out param to the method to be consistent with PHP patterns?
  • 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-28T19:04:22+00:00Added an answer on May 28, 2026 at 7:04 pm

    PHP has two main mechanisms for indicating and handling errors in your program flow:

    • Error Handling and Logging
    • Exceptions

    Which to pick depends on your personal preference. Exceptions are objects, so if you want to do OOP or come from another language that also uses Exceptions, you might want to use them. Non-Exception based error handling is for all those Notices, Warning and Errors PHP can emit, as well as you own variants of those. If you want to turn these into Exceptions, have a look at ErrorException.

    However, like you already mentioned: exceptions are for non-recoverable situations. They are not for managing regular control flow. Consequently, Exceptions are not some sort of standard mechanism to send back error messages to a caller, e.g. you should not do:

    class FooValidator
    {
        public function isValid($valueToValidate)
        {
            if ($this->satisfiesRules($valueToValidate) {
                return true;
            }
            throw new ValidationException('Foo didnt satisfy rule Bar');
        }
    }
    

    and they try/catch that in the caller. A failed validation is a recoverable situation.

    One option would be to introduce a Notification Object:

    class FooValidator
    {
        public function isValid($valueToValidate, Notification $notification)
        {
            if ($this->satisfiesRules($valueToValidate) {
                return true;
            }
            $notification->addMessage('Foo didnt satisfy rule Bar');
            return false;
        }
    }
    

    In the above example, the Validator returns only a Boolean but can collect additional information about why the validation failed in the passed Notification object. This is much cleaner than returning an Error Object from the call, because we dont have to check the return type. If the validation returns false, we know we can check the Notification object. Since objects are passed by reference, we dont need to return the object from the call but simply access the collected messages from the caller.

    • 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
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from

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.