PHP Libraries

PHP Libraries

A library is a single component of program code that can be used to solve an isolated problem.

Purpose of libraries

A professional programmer won't write all the code on his own. The level of a developer is determined not only by his knowledge of the language, but also by the ability to search and select the appropriate tools for solving a specific problem. If it is possible to use a high-quality ready-made solution, then this will be the best choice.

Out-of-the-box solutions help you write less code and focus on the project's domain. Most of the libraries are freely distributed on the Internet and are available for free use.

Typically a library is a collection of PHP scripts packed into an archive. During installation, the files are unpacked from the archive into a specific folder within your project. As a rule, one project uses at least several libraries.

When to use the library

When should you use and how to choose the library that is right for your purpose?

Ready-made solutions are designed to simplify work on common tasks. These are basic operations that are common in almost any web project.
Examples: sending emails, validating forms, working with graphics, resizing images, working with archives.
Therefore, naturally, libraries will not replace the entire code of your project, but will help in most of the routine actions.

The next thing to look out for when choosing a library is good documentation.
The documentation describes the library's capabilities and how to use it. If the documentation is incomplete, outdated, or not available at all, then using this library will be very difficult. You will have to independently understand its source code and see how everything works. In general, quality documentation is very important.

The second important quality of the library is how many programmers are already using this solution.
How to find out this indicator? You can focus on the number of stars on GitHub, the number of search results, or Google Trends data.
Why is it important? The more users a library has, the easier it will be to find an answer in a difficult situation or to understand the specifics of use.

The last criterion for choosing the right library is the set of features offered. To solve one problem, as a rule, there are several competing libraries. And they differ not only in documentation and user base, but also in general functionality. To avoid hammering nails with a microscope, try to determine if the chosen solution will not be too redundant and cumbersome for a particular task. And if so, then it might be better to find a simpler solution.

An example of connecting and using the library

Working with the library consists of three steps: installation, connection and use.
It's simple: you need to go to the site with the library, download the archive and unpack it into the folder with PHP scripts.
Then you need to connect scripts with library classes. Further in the code, new objects of these classes are created and their methods are called. This procedure is typical for any library.

Library dependencies

So we're using libraries to write less code and focus on what's important. The irony is that library authors do the same. In the library code, they themselves use other libraries to make their work easier.

Here's an example: we downloaded library "A", and it, in turn, uses library "B". At the same time, we did not download or install the library “B” code. Then you will not be able to use library "A", because it will not work until library "B" is additionally installed. These relationships between libraries are called dependencies.

It gets even more complicated when the dependency includes not only the name of the library, but also the specific version.