bodacydo
bodacydo

Reputation: 79369

How to install modern PHP packages?

How do I install modern PHP packages? I haven't used PHP for 5 years so everything seems new.

In particular I'm trying to install https://github.com/pda/pheanstalk. I downloaded the code, but when I try to

require_once 'Pheanstalk/Pheanstalk.php'

I get an error:

Fatal error: Interface 'Pheanstalk\PheanstalkInterface' not found
in /web/Pheanstalk/Pheanstalk.php

I found I should use use. When I try use Pheanstalk\Pheanstalk I get this error:

Fatal error: Class 'Pheanstalk\Pheanstalk' not found in /web/test.php on line 5

Can't I just download and use PHP code anymore like back in the day? How do I get these modern packages working? Packages seem to mention composer. Should I use that? Can't I just download code and use it? I don't want to depend on composer or any other package manager. I just want to run code.

Upvotes: 0

Views: 298

Answers (1)

Dany Caissy
Dany Caissy

Reputation: 3206

The modern way of installing packages is to use Composer.

It might seem scary at first, but it isn't such a big deal.

You should also be able to download and use the package yourself, if the creator made that possible, it should be explained in the documentation however.

There might be no "easy" way to install your package without composer if the package creator intended it that way. For this package in particular, the only instructions are for Composer, so it's safe to assume that it's the easiest way to install it.

Of course it's possible to use his code directly, but you'll need to know what you're doing and understand namespaces.

Upvotes: 3

Related Questions