How to Use Composer in Plain PHP

1480
Share:
how-to-use-composer-in-plain-php

Currently, there are many good frameworks available to be installed using composer. But there's a time when I just want to quickly test a PHP package. How is this possible? I will share how I do this in the article below.

Assuming you know some basic composer commands and have installed composer on your system, here are what you need to do:

  1. Install the package with composer
    Example:
    composer require whatsapp/chat-api
  2. After installing the package with composer, composer has generated an autoloader that you can include on your main PHP file.
    Example:
    require_once 'vendor/autoload.php`;
  3. Use the class(es) from the package without further includes.
    Example:
    $w = new WhatsProt($username, $nickname, $debug);
  4. That's it. Now you can try it with another package available on packagist.

Final Words

I hope that you now know how to composer in plain PHP without any Framework. If you run into any issues or have any feedback feel free to drop a comment below.

 

Tags
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *