Internals are voting on the Asymmetric Visibility RFC
HTML-код
- Опубликовано: 8 сен 2024
- Links:
- Share your vote: rfc.stitcher.i...
- The RFC: wiki.php.net/r...
- Limited by committee: stitcher.io/bl...
- My thoughts about the first version: stitcher.io/bl...
- PHP Cloneable: github.com/spa...
- The stream with Larry about property hooks: • Let's talk about prope...
Were you about to comment something about final? 👀
Yes, and i did it ANYWAY :D
@@CottonInDerTube 🤯
Making a class the read-only way and having better cloning methods is the way to go, it promotes class immutability 😊
public, private, protected, final, readonly, ... all short and easy.
But protected(set) is just breaking this "flow".
IMO it should be a single word 100% indicating what it does, or it should be implemented.
There's a fundamental difference between setTitle() and (clone) withTitle() and that is mutability vs immutability. I was really surprised, that you didn't even mention that.
I think the suggested syntax and especially the overlap with readonly is highly confusing..
Personally I would also prefer "clone with" but I'm fine with the following work around:
final readonly class SomeClass {
public function __construct(
public string $prop1,
public bool $prop2,
) {}
public function with(
string $prop1 = null,
bool $prop2 = null,
): self
{
return new self(
$prop1 ?? $this->prop1,
$prop2 ?? $this->prop2,
);
}
}
(to be used with named parameters)
I just don't like the syntax and prefer the c# one since it may allows for expension of functionality while keeping it a little bit more readable.
I total agree with you. I hope we can adapt the c# syntax for this.
How is the C# syntax for this?
@@ClaudiuMarginean public string Name { get; private set; }
With the above, the Name property has a public getter and a private setter.
@@HeavenNextHD yes, it looks like a C# wit public(set), but if is in PHP style I think is more clear with public-write.
Why not to utilize C# approach and existing property hooks ?
For instance public string Name { get; private set; }
property hooks and this is something I have been waiting for php for a good while, hopefully this is implemented aswell
i like how php becomes more and more like c#
Its more swift in this case
@@85bitsdeveloper yeah true but im just really opposed to switfs syntax in this case; i like csharps a lot better
I think they should allow readonly props to be changed within the class itself by default, in my mind the use case of readonly is there in order to prevent changes from outside the class anyway. now they have to reinvent the wheel but it's a tricky problem to begin with, I hope they won't perplex the syntax at least
Do we need this? I don‘t think so.
This is something that also exists in c# this is in my opinion a very powerful feature to have in php. I hope this get's implemented and this is nothing like read only properties which is also available in c# haha
When is PHP getting the native async feature?
Never, it already has coroutines
The RFC system is drive-by-shooting language design.
I didn't understand anything but I liked it, it's because I never used read-only thingy.
Actually we would need both "private set" and "clone with". the one doesn't exclude the other tbh
I don't like the extra "(set)" when reading from left to right.
Let us rather remove the writeonce behavior from readonly and add a separate writeonce keyword.
The private(set) syntax is also ugly.
Does PHP stand for PHP Hypertext Preprocessor or PHP Hotch Potch?
13:06 final is final until you realize you must remove it. :p
😂
So true!
the effort should be more focus on async rather than this kind of limited base use cases.
this is just a hacking way to make immutable to mutable, the RFC did not mention this as well, what a shame.
Please don't..... Now I know why people hate PHP.... Please copy syntax from C# or another new languages....
I mean... PHP started out with a syntax very similar with C then Objects were added by popular demand (with a java like syntax). Now we are kind of borrowing things from C#
Like the concept, hate the syntax.
Around 6:45 But isnt this book example a problem by design in the first place?
When the property on the object must be changes "sometimes" ... then its not read only, right?
True… to be totally correct you should say "this property is only allowed to change in specific contexts". Readonly doesn't allow that. So in a way you're making an argument for the RFC :)
Please dont
private function set
public function get
And no readonly
Ore am i dumb?
This syntax is not clear, it's counterintuitive, I don't like it. This, when used, is gonna make code less readable, it should be the other way. I feel like this is just progress for the sake of progress
the syntax is shit, I would like something like:
private writable $var;
private readable $var;