PHP code example of spatie / 7to5

1. Go to this page and download the library: Download spatie/7to5 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spatie / 7to5 example snippets


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;
            }
        };
    }
            
}

 
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();
    }
}

$converter = new Converter($pathToPhp7Code);

$converter->saveAsPhp5($pathToWherePhp5CodeShouldBeSaved);
 
$converter = new DirectoryConverter($sourceDirectory);

$converter->savePhp5FilesTo($destinationDirectory);
 
$converter = new DirectoryConverter($sourceDirectory);

$converter
   ->doNotCopyNonPhpFiles()
   ->savePhp5FilesTo($destinationDirectory);
 bash
$ composer global