# What License Does the PHP License Key Generator Use?

> Discover the license for the msbatal/php-license-key-generator. Learn if it uses LGPL 3.0 or LGPL 2.1 for your project needs.

- Repository: [Mehmet Selcuk Batal/php-license-key-generator](https://github.com/msbatal/php-license-key-generator)
- Tags: getting-started
- Published: 2026-03-07

---

**The PHP License Key Generator is released under the GNU Lesser General Public License (LGPL), with the source code in [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) explicitly declaring LGPL 3.0 while the repository distributes the LGPL 2.1 license text.**

The `msbatal/php-license-key-generator` repository provides a PHP library for generating cryptographically secure license keys. Before integrating this library into commercial or open-source projects, you must understand its licensing terms. The project adopts the GNU Lesser General Public License, a copyleft license specifically designed to allow linking with proprietary software while protecting the library itself.

## LGPL License Declaration in SunLicense.php

The definitive license identifier resides in the library's core class file. In [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) at lines 13–14, the class docblock contains:

```

@license https://opensource.org/licenses/lgpl-3.0.html The GNU Lesser General Public License, version 3.0

```

This `@license` annotation explicitly designates **LGPL 3.0** as the governing license. The annotation serves as the author's machine-readable intent, declaring that the library may be freely used, modified, and redistributed provided that any changes to the library itself remain under the same LGPL terms.

## The LICENSE File in the Repository Root

The repository also ships a `LICENSE` file containing the full legal text of the **GNU Lesser General Public License, version 2.1**. According to the file header at lines 1–5, this document represents LGPL v2.1. This creates a dual-reference scenario where the inline source code documentation points to version 3.0, while the bundled license text reflects the earlier 2.1 version.

## Reconciling LGPL Versions 2.1 and 3.0

When determining compliance obligations, recognize that the project references both versions:

- **Source code annotation**: [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) references LGPL 3.0 (the modern version with explicit patent grants and anti-tivoization provisions)
- **Bundled legal text**: The `LICENSE` file contains LGPL 2.1 (the older, widely-compatible version)

In practice, the more specific inline declaration in the PHP source typically governs as the author's explicit intent, meaning **LGPL 3.0** applies. However, both versions share identical core requirements: you may link the library with proprietary code, but you must provide source code for any modifications you make to the library itself.

## Verifying the License Programmatically

You can extract the license declaration at runtime using PHP's reflection API to parse the docblock from [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php):

```php
<?php
require_once 'SunLicense.php';

// Use reflection to fetch the docblock of the SunLicense class
$refClass = new ReflectionClass('SunLicense');
$docBlock = $refClass->getDocComment();

// Extract the @license line
if (preg_match('/@license\s+([^\s]+)\s+(.*)/', $docBlock, $matches)) {
    $url      = $matches[1];
    $license  = $matches[2];
    echo "License URL: $url\n";
    echo "License name: $license\n";
}
?>

```

Executing this script returns:

```

License URL: https://opensource.org/licenses/lgpl-3.0.html
License name: The GNU Lesser General Public License, version 3.0

```

This confirms that the library's source explicitly advertises LGPL 3.0, matching the docblock annotation in the class file.

## Compliance Requirements for Developers

Under the LGPL terms as implemented in this project, you retain the right to:

- **Use the library in proprietary applications** without releasing your entire source code
- **Modify and redistribute the library** for your specific needs
- **Link against the library** without infecting your application with GPL requirements

However, you must comply with these obligations:

- **Provide attribution** and include the LGPL license text when distributing the library
- **Release modifications** to the library itself under the same LGPL terms (version 3.0 as declared)
- **Enable replacement** of the library (the anti-tivoization requirement in LGPL 3.0 requires providing installation information if you distribute the library in a consumer device)

## Summary

- The PHP License Key Generator is licensed under the **GNU Lesser General Public License (LGPL)**
- The [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) file explicitly declares **LGPL 3.0** via the `@license` docblock at lines 13–14
- The repository's `LICENSE` file contains the full text of **LGPL 2.1**
- You may use the library in commercial projects provided you comply with LGPL terms regarding modifications and attribution
- Runtime verification is possible via PHP reflection parsing the `SunLicense` class docblock

## Frequently Asked Questions

### Is the PHP License Key Generator free for commercial use?

Yes. The LGPL permits use in proprietary commercial applications. You can link against the library or distribute it with your product without releasing your application's source code, provided you comply with the LGPL requirements regarding the library itself, such as providing the library's source code if you modify it and including the original copyright notices.

### Which LGPL version applies to this project, 2.1 or 3.0?

The source code docblock in [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) references LGPL 3.0, while the `LICENSE` file contains LGPL 2.1 text. In such cases, the inline code declaration typically takes precedence as the specific intent of the author, meaning LGPL 3.0 governs the licensing terms, though both versions share similar core requirements regarding library modifications and redistribution.

### Do I need to open-source my entire application if I use this library?

No. The "Lesser" in LGPL specifically allows linking with proprietary code without requiring you to release your application's source code. You only need to release source code for any modifications you make to the PHP License Key Generator library itself. You must also provide a way for users to obtain or replace the library, as required by the license terms.

### Where can I find the official license text in the repository?

The license is declared in two locations: the `@license` annotation in the class docblock within [`SunLicense.php`](https://github.com/msbatal/php-license-key-generator/blob/main/SunLicense.php) (lines 13–14), and the plain-text `LICENSE` file in the repository root. The PHP file indicates LGPL 3.0, while the LICENSE file contains the full text of LGPL 2.1.