GibboK
GibboK

Reputation: 73918

How reuse custom code among projects using PHP natively?

I am not familiar with PHP and having a background in C#.

I would like to know if PHP offers a way to share custom code among projects natively in the language (targeting the latest version of PHP)?

As in C# there is the possibility to create a custom DLL, that can be included in other projects when needed in order to reuse some code.

I understand there is the possibility to share common code from a versioning system such SVN and checkout sharedcode in each related project (as described in other answer on SO), but I am interested in the possibility in the language itself.

Upvotes: 1

Views: 110

Answers (3)

VolkerK
VolkerK

Reputation: 96159

I think with phar archives and composer you get as close to assemblies and nuget as you can get.

Upvotes: 1

fico7489
fico7489

Reputation: 8560

You can share code with composers packages, more on:

https://packagist.org/
https://getcomposer.org/

Upvotes: 0

Bilal
Bilal

Reputation: 2673

You should try a php framework like Laravel or Zend Framework. If you don't want to try a framework, there are couple of ways.

You can create a class of functions and then you can include that class wherever you want in your scripts. This is a simplest example.

namespaces are your friends. I highly recommend yo to have a look at here for PHP and here for a PHP framework.

Upvotes: 0

Related Questions