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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:38:19+00:00 2026-05-18T19:38:19+00:00

I have an interface called iIncident which defines a single method when() . when()

  • 0

I have an interface called iIncident which defines a single method when(). when() should return a DateTime object. I’m trying to decide what to do if $object->when() has no DateTime to return as might be the case just after an object is instantiated and before all its properties are set.

My choices are:

  1. return false
  2. throw some kind of Exception
  3. return some default DateTime like ‘9999-01-01’

My inclination is to go with an Exception since $object really can’t act as an incident until it knows when it occurred. I don’t want to return a default DateTime because it complicates comparisons and it’s not true. And I don’t really want to return false because then I have to check for it every time I call the method- but if that is the preferred method, I guess I will.

Is throwing an exception the best way? And is there a predefined exception type I should use (none of the SPL ones struck me as particularly appropriate- but that might just indicate my lack of experience)?

  • 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-18T19:38:19+00:00Added an answer on May 18, 2026 at 7:38 pm

    I think the problem is that you’re allowing an object to be created in an inconsistent state. If the object should be able to create date values, then it should receive all the dependencies it needs to do so in its constructor instead of through properties. If this is not possible, then you should consider trying to encapsulate the construction process through a factory (or factory method).

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

Sidebar

Related Questions

I have an interface called Dictionary which has a method insert() . This interface
I have an interface called ICommand from which various classes inherit. These classes all
I have a property called IsSecureConnection that is part of my object's interface. This
I have an interface called ICatalog as shown below where each ICatalog has a
I have an interface for Client Registration called IRegistrationService. This contains one method called
I have an Interface called IStep that can do some computation (See Execution in
I'm having a small problem in Java. I have an interface called Modifiable. Objects
I have an interface that I have defined in C++ which now needs to
I have two questions 1) my interface i have interface called IRegister and within
I have an interface called IAddress, and a class called Address that handles street,

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.