On 26/02/2024 19:02, Frederik Bosch wrote:

That's how it always has been, no? So in your example, short code abbreviated form would not work. One has to write a block.

public string$fullName { set=> [$this->first, $this->last] = explode <http://www.php.net/explode>(' ', \ucfirst <http://www.php.net/ucfirst>($value)); // error, $fullName is a string, returning array
     }
public string$fullName { set{
             [$this->first,  $this->last]  =  explode  <http://www.php.net/explode>(' 
',  \ucfirst  <http://www.php.net/ucfirst>($value));  // no error, not returning
         }
     }


I think the intention is that both the block and the arrow syntax would have any return value ignored, as happens with constructors, for example. Note that in PHP, there is actually no such thing as "a function not returning a value", even a "void" function actually returns null; so if the return value was treated as meaningful, your second example would give an error "cannot assign null to property of type string".

However, as noted in a previous message, I agree that the short form meaning "the value returned is saved to the backing field" is both more expected and more useful.

The "yield" idea is ... interesting. I think personally I find it a bit too magic, and too cryptic to be more readable than an explicit assignment. Opinions may vary, though.

Regards,

--
Rowan Tommins
[IMSoP]

Reply via email to