tags:

views:

66

answers:

2

Possible Duplicate:
Can I include code into a PHP class?

Hello,

I have some third-part php files that I would like to include as classes in my application. The problem is those files keep changing and they are not OOP, just a bunch of functions. To keep them updated and to work in my framework I have to use them in a class, so I would like to include the file and access it via -> operator:

Example:

class Vendor {
    include("../vendor/functions.php");
}

and then:

$vendor = new Vendor();
$vendor->foorbar();

Any ideas ?

+1  A: 

I think that the best way to go would be to modify (automated) the function-files to include

namespace VendorName;

That way the global namespace is not polluted but you have access to the functions. Calls my be performed by:

VendorName\FunctionName($arguments);
nikic
Well, I can't modify vendor files in any form. The problem is to use them as-is
Fernando Barrocal
A: 

I presume that those third-party files are not going to be injected into your app in any automated fashion and you just want to easy the task of having them available in your framework while you're able to upgrade to newer versions. In such case, I recommend you use what Subversion calls "vendor branches". It's just a concept you can use it whatever your source control tool is. To sum up:

  • You download the third-party code and store it into your code repository.
  • You copy the code into your app and modify it to suit your needs.
  • When the vendor releases a new version, you update the stored code.
  • You use your version control software to copy the changes into your app.
Álvaro G. Vicario
In fact, the whole point, is to have this functionality, to have the "function files" as is, and my app able to use them. Zero maintenance on new function files ...
Fernando Barrocal