Git Product home page Git Product logo

rfcoperatoroverloads's People

Contributors

danack avatar

Watchers

 avatar

Forkers

jordanrl

rfcoperatoroverloads's Issues

Needs a $left example

most of the good examples of that involve two objects
but it would probably be matrix multiplication
where it can accept a multi-dimensional array as a "matrix"
so $result = [1, 0, 1] * $matrix
since rows of matrix A needs to equal columns of matrix B

add words on why generics don't help.

https://en.reddit.com/r/PHP/comments/rv11fc/operator_overloading_rfc_is_in_voting_what_are/hr316wy/

–]john7 points 2 days ago*
I can't wait for it. The reason is that I use lots of lazy evaluations; old version of example is here.

So I could have a function like this:

function doSomething(int|LazyValue $param): int {
return $param + 42;
}

but without operator overload:

function doSomething(int|LazyValue $param): int {
if ($param instanceof LazyValue) {
$param = $param->getValue();
}

return $param + 42;

}

Updated:

I would prefer for RFC to require interfaces, if possible:

interface Addable
{
public function add(int|float|Addable $param): int|float|Addable
}

End result:

function doSomething(int|Addable $param): int {
return $param + 42;
}

Interfaces would make easier job for static analysis, allow ctrl+click to find all Addable implementations and avoid some WTF situations in older apps with __add() method.

[–]Danack 2 points 2 days ago
I would prefer for RFC to require interfaces, if possible:

Did read the reasons why that isn't appropriate in the RFC ?

https://wiki.php.net/rfc/user_defined_operator_overloads#why_not_interfaces

permalinkembedsaveparenteditdisable inbox repliesdeletereply

[–]john 1 point 1 day ago*
I did, but I think it is mostly because of lack of generics.

For example:

interface Addable
{
public function add(T $param): T
}

class Money implements Addable<int|Money>{}

But I could be wrong, that's why I said if possible; maybe other contributors can come up with some idea.

permalinkembedsaveparentreportgive awardreply

[–]Danack 3 points 1 day ago
That doesn't help anything. If you're using an interface as a type e.g.

function foo (Addable $x, int $y)
{
return $x + $y;
}
You can't tell if the code is valid or not from the interface.

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.