Re: [PHP-DEV] Allowing class properties to remain Uninitialized as a default value.

2025-06-05 Thread Faizan Akram Dar
On Thu, 5 Jun 2025, 13:56 Bradley Hayes, wrote: > Here is another way to think about it, trying to make the arguments > optional not have a new value type. > > Optional arguments currently requires a default value. > > Assigning values to properties is truly optional but we cant reflect this > in

Re: [PHP-DEV] Allowing class properties to remain Uninitialized as a default value.

2025-06-04 Thread Bradley Hayes
Here is another way to think about it, trying to make the arguments optional not have a new value type. Optional arguments currently requires a default value. Assigning values to properties is truly optional but we cant reflect this in the constructor parameters. class DTO { public function

Re: [PHP-DEV] Allowing class properties to remain Uninitialized as a default value.

2025-06-04 Thread Bradley Hayes
Hey Claude, i did think of the same thing you proposed and I cover that in the gihub issue I linked to. This doesnt replicate the uninitialized state. Doing ti with custom classes or enums means now not only are forced to manually check each property everywhere it might be used you also have to wr

Re: [PHP-DEV] Allowing class properties to remain Uninitialized as a default value.

2025-06-04 Thread Claude Pache
> Le 3 juin 2025 à 06:22, Bradley Hayes a écrit : > > Uninitialized properties are really useful. > Being skipped in foreach loops and JSON encoded results and other behaviours > around uninitialized properties save a lot of time wasted on basic checks and > uncaught logical mistakes around n

Re: [PHP-DEV] Allowing class properties to remain Uninitialized as a default value.

2025-06-03 Thread Bradley Hayes
Could be handy to allow this in normal functions too (but this it not the main use case and could be disallowed): public static function get(string $name, mixed $default = uninitialized): string { $value = getenv($name); if ($value === false) { return $default; // throws uninitiali

[PHP-DEV] Allowing class properties to remain Uninitialized as a default value.

2025-06-02 Thread Bradley Hayes
Uninitialized properties are really useful. Being skipped in foreach loops and JSON encoded results and other behaviours around uninitialized properties save a lot of time wasted on basic checks and uncaught logical mistakes around null values. With the introduction of named arguments and promoted