PHPackages                             spatie/7to5 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. spatie/7to5

AbandonedArchivedLibrary

spatie/7to5
===========

Convert PHP 7 code to PHP 5 code

1.3.0(8y ago)17525.6k↓50%333MITPHPPHP ^5.6|^7.0|^7.1

Since Feb 19Pushed 7y ago7 watchersCompare

[ Source](https://github.com/spatie/7to5)[ Packagist](https://packagist.org/packages/spatie/7to5)[ Docs](https://github.com/spatie/7to5)[ RSS](/packages/spatie-7to5/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (13)Used By (3)

**This package has been abandoned**

We are not maintaining this package any more. Feel free to fork our code and maintain your own copy.

Convert PHP 7.0 code to PHP 5 code
==================================

[](#convert-php-70-code-to-php-5-code)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8c22d0bd3d74744ad90ad473d3eb804e613a920fa3259194223613e12794e6a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f37746f352e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/7to5)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/89622ee6090a9d8aae5d8cde4f71024453d5f2119ecde3d43e790d7256d91cb9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f37746f352f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/7to5)[![Quality Score](https://camo.githubusercontent.com/815f4db3576f01bcf806a3c9f38ea9438c966d30eec227d6b6fded905c74c099/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f37746f352e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/7to5)[![Total Downloads](https://camo.githubusercontent.com/34175365512e754cfec2e83764fa3d7540e66a47300f1c686e86472eb0253309/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f37746f352e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/7to5)

This package can convert PHP 7.0 code to PHP 5. This can be handy when you are running PHP 7 in development, but PHP 5 in production.

You can convert an entire directory with PHP 7.0 code with a the console command:

```
php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code}
```

Here's an example of what it can do. It'll convert this code with PHP 7 features:

```
class Test
{
    public function test()
    {
        $class = new class() {
            public function method(string $parameter = '') : string {
                return $parameter ?? 'no parameter set';
            }
        };

        $class->method();

        $anotherClass = new class() {
            public function anotherMethod(int $integer) : int {
                return $integer > 3;
            }
        };
    }

}
```

to this equivalent PHP 5 code:

```
class AnonymousClass0
{
    public function method($parameter = '')
    {
        return isset($parameter) ? $parameter : 'no parameter set';
    }
}
class AnonymousClass1
{
    public function anotherMethod($integer)
    {
        return $integer < 3 ? -1 : ($integer == 3 ? 0 : 1);
    }
}
class Test
{
    public function test()
    {
        $class = new AnonymousClass0();
        $class->method();
        $anotherClass = new AnonymousClass1();
    }
}
```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Installation
------------

[](#installation)

If you plan on use [the console command](#using-the-console-command) we recommend installing the package globally:

```
$ composer global require spatie/7to5
```

If you want to [integrate the package in your own code](#programmatically-convert-files) require the package like usual:

```
$ composer require spatie/7to5
```

The conversion process
----------------------

[](#the-conversion-process)

This package converts PHP 7 code to equivalent PHP 5 code by:

- removing scalar type hints
- removing return type hints
- removing the strict type declaration
- replacing the spaceship operator by an equivalent PHP 5 code
- replacing null coalesce statements by equivalent PHP 5 code
- replacing group use declarations by equivalent PHP 5 code
- replacing defined arrays by equivalent PHP 5 code
- converting anonymous classes to regular classes

Because there are a lot of things that cannot be detected and/or converted properly we do not guarantee that the converted code will work. We highly recommend running your automated tests against the converted code to determine if it works.

Using the console command
-------------------------

[](#using-the-console-command)

This package provides a console command `php7to5` to convert files and directories.

This is how a entire directory can be converted:

```
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code}
```

Want to convert a single file? That's cool too! You can use the same command.

```
$ php7to5 convert {$sourceFileWithPHP7Code} {$destinationFileWithPHP5Code}
```

By default the command will only copy over `php`-files. Want to copy over all files? Use the `copy-all` option:

```
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code} --copy-all
```

By default the command will only convert files with a php extension, but you can customize that by using the `--extension` option.

```
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code} --extension=php --extension=phtml
```

If necessary, you can exclude directories / files.

```
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code} --exсlude=cache
```

Programmatically convert files
------------------------------

[](#programmatically-convert-files)

You can convert a single file by running this code:

```
$converter = new Converter($pathToPhp7Code);

$converter->saveAsPhp5($pathToWherePhp5CodeShouldBeSaved);
```

An entire directory can be converted as well:

```
$converter = new DirectoryConverter($sourceDirectory);

$converter->savePhp5FilesTo($destinationDirectory);
```

By default this will recursively copy all to files to the destination directory, even the non php files.

If you only want to copy over the php files do this:

```
$converter = new DirectoryConverter($sourceDirectory);

$converter
   ->doNotCopyNonPhpFiles()
   ->savePhp5FilesTo($destinationDirectory);
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Hannes Van De Vreken](https://twitter.com/hannesvdvreken)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

Original idea: [Jens Segers](https://twitter.com/jenssegers)

Support us
----------

[](#support-us)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~78 days

Recently: every ~50 days

Total

11

Last Release

2949d ago

Major Versions

0.0.3 → 1.0.02016-03-28

PHP version history (2 changes)0.0.1PHP ^5.6|^7.0

1.1.0PHP ^5.6|^7.0|^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (95 commits)")[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (8 commits)")[![fluxuator](https://avatars.githubusercontent.com/u/950283?v=4)](https://github.com/fluxuator "fluxuator (4 commits)")[![LasseRafn](https://avatars.githubusercontent.com/u/2689341?v=4)](https://github.com/LasseRafn "LasseRafn (1 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (1 commits)")[![tamaspanczel](https://avatars.githubusercontent.com/u/28923246?v=4)](https://github.com/tamaspanczel "tamaspanczel (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![Tjoosten](https://avatars.githubusercontent.com/u/5157609?v=4)](https://github.com/Tjoosten "Tjoosten (1 commits)")[![alexbowers](https://avatars.githubusercontent.com/u/842974?v=4)](https://github.com/alexbowers "alexbowers (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")

---

Tags

spatieconvertsyntaxtreePHP7abstract7to5

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-7to5/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-7to5/health.svg)](https://phpackages.com/packages/spatie-7to5)
```

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M186](/packages/spatie-laravel-backup)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M255](/packages/laravel-dusk)[humbug/php-scoper

Prefixes all PHP namespaces in a file or directory.

7963.0M34](/packages/humbug-php-scoper)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2592.8M262](/packages/ssch-typo3-rector)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
