ziadoz / awesome-php

A curated list of amazingly awesome PHP libraries, resources and shiny things.
Do What The F*ck You Want To Public License
30.79k stars 5.06k forks source link

Added php-defer/php-defer #1025

Closed bkrukowski closed 4 years ago

bkrukowski commented 4 years ago

Library

https://github.com/php-defer/php-defer

Golang docs

https://blog.golang.org/defer-panic-and-recover https://tour.golang.org/flowcontrol/12

Example

<?php

function helloGoodbye()
{
    defer($_, function () {
        echo "goodbye\n";
    });

    defer($_, function () {
        echo "...\n";
    });

    echo "hello\n";
}

echo "before hello\n";
helloGoodbye();
echo "after goodbye\n";

// Output:
//
// before hello
// hello
// ...
// goodbye
// after goodbye
ziadoz commented 4 years ago

This looks interesting. Thanks.

bkrukowski commented 4 years ago

Thanks :)