Including a file in a PHP class

I was trying to figure out how I could manage the premium logic for my freemium Better Together for OpenCart module.  You can’t just require a block of code in the middle of a PHP Class:

class SomeClass {  
  // NOT ALLOWED! 
  premium_file = "premium.php";
  if (file_exists($premium_file)) {
    require($premium_file);
  }

So I cooked up another method that I documented in this StackOverflow post about how to include code into a PHP class.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.