PHP code example of typhoon / formatter

1. Go to this page and download the library: Download typhoon/formatter 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/ */

    

typhoon / formatter example snippets


format(null);                 // null
format(true);                 // true
format(42);                   // 42
format("it's fine");          // 'it\'s fine'
format([1, 2, 3]);            // list{1, 2, 3}
format(['a' => 1, 'b' => 2]); // array{a: 1, b: 2}
format((object)['x' => 1]);   // object{x: 1}
format(Status::Active);       // Status::Active
format(new MyClass());        // MyClass
format(fn() => null);         // function@src/foo.php:12()

formatClass(MyClass::class); // MyClass
formatClass(new MyClass());  // MyClass
formatClass(new class {});   // class@src/foo.php:42

formatFunction('strlen');                       // strlen()
formatFunction('MyClass::myMethod');            // MyClass::myMethod()
formatFunction([MyClass::class, 'myMethod']);   // MyClass::myMethod()
formatFunction(fn() => null);                   // function@src/foo.php:12()
formatFunction(new MyInvokable());              // MyInvokable()

formatParameter('myFunction', 'value');  // myFunction($value)
formatParameter('myFunction', 0);        // myFunction($0)

formatProperty(MyClass::class, 'name');  // MyClass::$name
formatProperty(new MyClass(), 'name');   // MyClass::$name