Re: [Discussion][RFC Idea] Cast Variables by Reference
| From: | Alexandru Pătrănescu | Date: | Mon, 07 Jul 2025 16:47:14 +0000 |
| Subject: | Re: [Discussion][RFC Idea] Cast Variables by Reference | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127941@lists.php.net to get a copy of this message | ||
On Mon, Jul 7, 2025 at 7:25 PM Joseph Leedy <joseph+php@josephleedy..dev>
wrote:
>
> As a developer, I would like to have variables of one type cast to another
> type automatically so that I do not need to assign the variable to itself..
>
>
> What if we could do this instead?
>
> ```php
> $price = '5.0123';
> ...
> (float) $price;
>
> var_dump($price); // Result:
float: 5.0123
> ```
>
>
This is valid code now, and does not perform the cast.
You need to use a slightly different syntax, maybe (float)&$price; that
is an error now.
--
Alex