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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:13:05+00:00 2026-05-20T18:13:05+00:00

I have an admin process that scans some directories and files to see if

  • 0

I have an admin process that scans some directories and files to see if certain php files extend an abstract class. So I have a directory structure as follows.

/models
/models/Random.php
/models/Payment/Abstract.php
/models/Payment/Cash.php
/models/Payment/Credit.php
/models/Payment/Cheque.php

cash.php, credit.php and cheque.php extends abstract.php which are named as MyApp_Payment_Cash, MyApp_Payment_Credit, MyApp_Payment_Cheque.php and MyApp_Payment_Abstract.
I need to produce an array that is array('Cash', 'Credit', 'Cheque');. I have code as follows:

$aModules = array();
foreach (new DirectoryIterator(APPLICATION_PATH . '/models/Payment') as $oFile) {
     if (preg_match('/^(.*)\.php$/', $oFile->getFileName(), $aMatches)) {
          $sName = sprintf('MyApp_Payment_%s', $aMatches[1]);
          if ($sName instanceof MyApp_Payment_Abstract) {
              $aModules[] = $sName;
          }
     }
}

But that obviously doesn’t work (instanceof doesn’t work this way on strings). I tried also tried try… catch on new $sName() but PHP threw a fatal when it tried new MyApp_Payment_Abstract.

As you might gather I’m trying to build an extendable payment system that allows new payment methods to be added in the future.

I could change my regex to something like /^(?!Abstract|.*)\.php$/ but that seems a rather blunt instrument for a true test.

  • 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-20T18:13:06+00:00Added an answer on May 20, 2026 at 6:13 pm

    I could not find an effective way of dealing with this so I trusted that all the files were in the correct place and used:

    if ($oFile->isFile() && preg_match('/^(.*)(?<!Abstract)\.php$/', $oFile->getFileName(), $aMatches)) {
    

    Not ideal as I would like to test with instanceof but workable.

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

Sidebar

Related Questions

I have a standard Django Admin page that is used to upload multiple files.
I have an authenticated directory in my site that has a bunch of directories
I have an admin form that lets users create entities that require an image.
I have an admin system and a user system on my website. Some data
Hey guys I have an admin page that checks if you are admin before
Hi Sitepoint wizard people, Say we have an admin application that has multiple users
I'm trying to run a vb script using process.start() as another user that have
We have a legacy 3rd party program that is failing with the error Class
I have a very complicated problem that occurs only for non-admin windows user. I
I have an admin that is almost completely ajax driven. When the page loads

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.