Search code examples
phpphar

Do Phar files in PHP equate to Assemblies in Dot Net?


I am a Dot Net programmer that is now learning PHP just for fun and to see how PHP handles certain things. For me the basic concepts are easy because they are more or less common to web programming and programming in general like OOP, Sessions, Security etc. However there seem to be some areas which are confusing me as PHP is built differently from Dot Net world. One of those things is Phar files. In Dot Net we are so used to creating loosely coupled assemblies that we re-use everywhere. However in PHP most of the books that I have read and code I have seen will just create classes and use them directly in the project. The confusion that I have right now is:

  • Are Phar files simmilar to dll files in Dot Net world?
  • If so why they are not used often?
  • Is their any performance hit when using Phar file?
  • Can I use Phar files aggressively to create re-usable code libraries?

Kindly guide me if you have a lot of PHP experience, I want to know how the experts of PHP handle things.


Solution

  • Are Phar files simmilar to dll files in Dot Net world?

    No, they're not. They're just archives of plain-text source code

    If so why they are not used often?

    Because they're extremely new

    Is their any performance hit when using Phar file?

    No, they're just source code, gzipped. After extraction, they're just source code.

    Can I use Phar files aggressively to create re-usable code libraries?

    What does "aggressively" mean? You cannot aggressively use tarballs. Use them or don't use them, they're just an archiving format for distributing code, whether library or application, in a single file. You limit your audience by using them, as they only work with relatively new versions of PHP.