Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PawelSuwinski opened this issue Oct 26, 2022 · 3 comments
Open

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

PawelSuwinski opened this issue Oct 26, 2022 · 3 comments
Assignees

Comments

@PawelSuwinski
Copy link

PawelSuwinski commented Oct 26, 2022

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()
@PawelSuwinski PawelSuwinski changed the title strict_types=1 makes pipe-operator less agile strict_types=1 makes pipe-operator less agile [question] Oct 26, 2022
@buismaarten
Copy link

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

Hope this helps..

@sebastiaanluca
Copy link
Owner

@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.

@sebastiaanluca
Copy link
Owner

sebastiaanluca commented Nov 24, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants