GithubHelp home page GithubHelp logo

sebastiaanluca / php-pipe-operator Goto Github PK

View Code? Open in Web Editor NEW
283.0 7.0 13.0 74 KB

Method chaining for any value using any method.

Home Page: https://sebastiaanluca.com

License: MIT License

PHP 100.00%
php pipe operator rfc take chain method

php-pipe-operator's Issues

Why not a pipe() function?

Is there a specific reason you went for a pipe class instead of a simple pipe function, like:

function pipe() {
    $args = func_get_args();
    $result = $args[0];
    $functions = array_slice($args, 1);
    foreach ($functions as $function) {
        $result = $function($result);
    }
    return $result;
}

Just curious. ^^

strict_types=1 makes pipe-operator less agile [question]

Hi

It is very nice piece of work, I am using pipe-operator in my projects. It really rocks, especially in combination with symfony expression language.

When I upgraded to 5.x within php8 migration I noticed that some of my expressions need to be fix because of strict_types=1.

I am wondering is declaring strict_types=1 is good for pipe-operator? What were the arguments for doing this?

As I understand the purpose of the pipe-operator it to make the code flow :), get it more compact and agile and so does the php coercive mode which is good thing in specific cases, changing it to strict_types in my opinion takes pipe-operator one step back in terms of agile.

For example:

class A 
{
  public function __toString(): string
  {
    return '[]';
  }
}
take(new A())->json_decode()->get();

On version 3-4.x it executes with no errors, on version 5.x it ends with:

PHP Fatal error:  Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, A given in /home/psuw/xtm/projekty/portal/portal/vendor/sebastiaanluca/php-pipe-operator/src/Pipe.php:37

Of course it will work but it is not so compact:

take((string) new A())->json_decode()->get();

symfony expression language:

take(a.__toString()).json_decode().get()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.