rfcoperatoroverloads's People
Forkers
jordanrlrfcoperatoroverloads'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
Start off with how python uses it.
Start off with how python uses it.
Needs more words on maths....
or other problem domains that are currently hard to solve in PHP.
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.
Add example that uses interfaces explicitly.
at least one person preferred static methods
https://externals.io/message/116767#116788
I'm also not a fan of the OperandPosition approach, though I could probably
live with it. The previous approach using static methods seemed more
natural to me, especially when it comes to operators that do not typically
commute (e.g. subtraction).
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.