sebastiaanluca/php-pipe-operator

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

Opened this issue · 3 comments

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

I made a similar project like this which doesn't use strict_types=1. See: https://github.com/boostphp/pipe-operator

Hope this helps..

@PawelSuwinski Cześć! Thanks for the suggestion, I'll try to find some time soon to remove the strict type declaration and release a new version.

@buismaarten I mean it's all open-source yeah, but not sure what to think of exploiting an older, outdated version of my package under another name without any reference to the original package and everything exactly the same. That doesn't seem ethical or respectful, especially if you keep downvoting issues and mentioning yours as a good replacement in this repository's issues.

@PawelSuwinski I'm not finding any time soon to get this done 😅 If you want, feel free to submit a PR that removes the declaration and adds a test asserting the use of the change (your example). I think it'd only be necessary in the Pipe class.