koen's avatar

Koen van Meijeren

koen

Member since

90

Total Reputation

1

Total Arguments

16

Total Votes for Arguments

Arguments and votes

3

Asymmetric visibility allows for properties that are publicly readable but privately writable. This means that while the value can be accessed from anywhere, it can only be changed in controlled, intentional ways. By making a property writable only within a private scope, you can ensure that only specific methods or functions can modify it. This reduces the risk of unintended side effects from external code, which can potentially corrupt the state of the object.

Share:
Read the RFC: Asymmetric Visibility v2 faisal avatar
faisal
voted yes
3

It adds complexity, it can be confusing, but i think it's an important step forward for php to implement such feature.

For the readonly vs. asymmetric visibility discussion: you can mix them up since they aim a different goals (write-once vs writing from).

Share:
Read the RFC: Asymmetric Visibility v2 jorisvaesen avatar
jorisvaesen
voted yes
5

I'm conflicted about this RFC. I definitely have use cases for "publicly readable and privately writable" properties. Especially since we still don't have clone with. I'm a afraid of the overlap between asymmetric visibility with readonly properties. By introducing asymmetric visibility, we make readonly properties essentially useless (asymmetric visibility can do the same, and more). I wonder how the community will deal with such a change: readonly properties were introduced in PHP 8.1, what happens if they become obsolete only a couple of versions later?

Despite my worry, I like this proposal on its own, and it would actually be useful to me in many cases. In the end, I'm inclined more towards voting yes than no.

Share:
Read the RFC: Asymmetric Visibility v2 Contributor brent avatar
brent
voted yes
4

JavaScript has this, and I've never found the lack of parentheses confusing there. If anything, I think the currently-required wrapper parentheses in PHP add cognitive load when parsing out a statement.

Share:
Read the RFC: new MyClass()->method() without parentheses zeb avatar
zeb
voted yes
16

Every time I find myself typing new MyClass() and than returning back and adding those parentheses. It would be good to reduce this friction and make PHP coding flow smoother.

Share:
Read the RFC: new MyClass()->method() without parentheses pronskiy avatar
pronskiy
voted yes
20

Often, I add static methods to some classes in order to improve readability when I instantiate a new class; the ability of chaining methods directly to the constructor, without the unnecessary parenthesis boilerplate, would remove the need for that.

Share:
Read the RFC: new MyClass()->method() without parentheses reddalo avatar
reddalo
voted yes
19

Nice addition, but I would change syntax:

class User 
{
    public string $name {
        set($value) {
            if (strlen($value) === 0) {
                throw new ValueError("Name must be non-empty");
            }
            return $value;
        }
    }
 
    public function __construct(string $name) {
        $this->name = $name;
    }
}
Share:
Read the RFC: Property Hooks yoshi129 avatar
yoshi129
voted yes
36

This is good to have.

Properties are useful for exchanging (reading and writing) single values. Properties are good for data binding, etc.

With this RFC we can implement:

  • Validation
  • Trigger events
  • Call methods if there is more to do

Update: About the $field I am not sure. Having a separate backing field can have some advantages.

Share:
Read the RFC: Property Hooks maz avatar
maz
voted yes
88

With First-class callable syntax available since 8.1, it would now be possible to write it as below, which is much better then string names of functions:

$result = "Hello World"
    |> htmlentities(...)
    |> str_split(...)
    |> fn($x) => array_map(strtoupper(...), $x)
    |> fn($x) => array_filter($x, fn($v) => $v != 'O');
Share:
Read the RFC: The Pipe Operator pronskiy avatar
pronskiy
voted yes
22

I could have used it multiple times for array transformations. But the RFC still built on really ancient PHP behaviour (mapping functions as strings) and should be redone by fosucing only on modern syntax:

  • closures and short closure: |> fn($x) => array_filter($x, fn($v) => $v != 'O')
  • first class callable syntax: |> str_split(...)
Share:
Read the RFC: The Pipe Operator tpetry avatar
tpetry
voted yes
65

For me, the most important argument is that the pipeline pattern is a tried and tested pattern, that this RFC builds upon. A couple of examples:

This RFC adds syntax to make using these kinds of pattern much more convenient.

On top of that, there's the argument that multiple modern languages support a pipe operator:

Finally, I've had numerous occasions where a pipe operator would simplify my own code — I have more than a handful real life cases where this would be useful.

Share:
Read the RFC: The Pipe Operator Contributor brent avatar
brent
voted yes
1

Separation of what and how. Besides this, it could pave the way for https://en.wikipedia.org/wiki/Multiple_inheritance which is also undesirable

Share:
Read the RFC: Interface Default Methods koen avatar
koen
voted no
75
  • Interface shall stay light, pure contracts defining expectations, else they are just abstract classes with multi-inheritance.
  • If multi-inheritance is the subject, a specific RFC shall be done on this.
  • An other away might be to dig back this RFC to add interface to traits: https://wiki.php.net/rfc/traits-with-interfaces
Share:
Read the RFC: Interface Default Methods victor avatar
victor
voted no
39

PHP is evolving. There are new concepts added to many programming languages to ease writing and reading (more important!). PHP should focus more on developer experience (but not for legacy projects that get never upgraded to PHP 8+).

Share:
Read the RFC: Short Closures 2.0 eugen avatar
eugen
voted yes
121

At least once a week, I throw away an array_map because it ended up looking too bloated and go with a classic foreach instead. Short Closures 2.0 without the use(...) block would've solved this problem, just 2 votes...

Share:
Read the RFC: Short Closures 2.0 davi avatar
davi
voted yes
57
  1. Separation of what (interface) and how (class/trait)
  2. More balanced vote chart, now it's too green
Share:
Read the RFC: Interface Default Methods jacek avatar
jacek
voted no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!