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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:35:58+00:00 2026-05-15T10:35:58+00:00

It’s really irking me that PHP considers the failure to instantiate an object a

  • 0

It’s really irking me that PHP considers the failure to instantiate an object a Fatal Error (which can’t be caught) for the application as a whole. I have set of classes that aren’t strictly necessary for my application to function–they’re really a convenience. I have a factory object that attempts to instantiate the class variant that’s indicated in a config file.

This mechanism is being deployed for message storage and will support multiple store types:

  • DatabaseMessageStore
  • FileMessageStore
  • MemcachedMessageStore
  • etc.

A MessageStoreFactory class will read the application’s preference from a config file, instantiate and return an instance of the appropriate class.

It might be easy enough to slap a conditional around the instantiation to ensure that class_exists(), but MemcachedMessageStore extends PHP’s Memcached class. As a result, the class_exists() test will succeed–though instantiation will fail–if the memcached bindings for PHP aren’t installed.

Is there any other way to test whether a class can be instantiated properly? If it can’t, all I need to do is tell the user which features won’t be available to them, but let them continue one with the application.

  • 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-15T10:35:59+00:00Added an answer on May 15, 2026 at 10:35 am

    As far as I can tell, this can’t be done short of PHP 5.3. What I did instead was to make the factory class check for the existence of Memcached before instantiating the class that extends it. It’s clumsy and far too brittle for my tastes, but it’s working for now. When we upgrade to 5.3, I’ll rework it a bit.

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

Sidebar

Related Questions

No related questions found

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.