Re: [PHP-DEV] Constructor promoted property and default value

2023-10-25 Thread Robert Landers
On Mon, Oct 23, 2023 at 6:22 PM Pierre  wrote:
>
> Le 23/10/2023 à 18:11, Saki Takamachi a écrit :
> >> If I understand your use case properly, you should be confused by 
> >> properties with default values that are not constructor-promoted as well ? 
> >> Am I wrong ? In this case, your problem is not with promoted properties ?
> > If we specify it the way you say, the initial values of the constructor 
> > arguments will be available even when the constructor is not called.
> >
> > Such behavior felt a little counterintuitive.
>
> Which then would simply be the same behavior as properties when not
> promoted but declared in the class body instead:
>
> ```php
>
> class Foo
> {
>  public $val = 'abc';
> }
>
> $redis_foo = serialize(new Foo());
>
> $foo = unserialize($redis_foo);
> var_dump($foo->val);
> // string(3) "abc"
>
> ```
>
> Right ?
>
> What's the most disturbing in my opinion is that: `class Foo { public
> string $val = 'abc' }` and `class Foo { public function
> __construct(public string $val = 'abc' ) {}}` don't yield the same
> behavior at the time.
>
> Regards,
>
> --
>
> Pierre
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>

Here's a nice and simple example:

https://3v4l.org/DU0tG

class A {
public string $default = 'default';
}

class B {
public function __construct(public string $default = 'default') {}
}

$a = new A();
echo "Original A: {$a->default}\n";
$b = new B();
echo "Original B: {$b->default}\n";

$a = (new ReflectionClass($a))->newInstanceWithoutConstructor();
echo "New A: {$a->default}\n";
$b = (new ReflectionClass($b))->newInstanceWithoutConstructor();
echo "New B: {$b->default}\n"; // crashes here

Robert Landers
Software Engineer
Utrecht NL

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] Change the signature of odbc_connect

2023-10-25 Thread Saki Takamachi
Hi, Máté

Thank you for your feedback! After seeing your email, I decided to start 
implementing it.

I have already created a pull request for a bug fix that does not require a 
signature change, and I plan to update it.

Regards.

Saki
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



[PHP-DEV] Request of RFC karma

2023-10-25 Thread Alessandro Rosa
Hi,

I would like receiving the wiki RFC Karma for my account, in order to
submit an RFC on the built-in "empty" function.
My account is alessandro.a.rosa_gmail.com

Thanks in advance,

Alessandro Rosa
WEB : http://alessandrorosa.altervista.org
LINKEDIN : https://www.linkedin.com/in/alessandro-rosa-9b7ba67b/


Re: [PHP-DEV] Custom object equality

2023-10-25 Thread G. P. B.
I am just going to put this out there, but I will vote against any RFC
which provides access to userland to overload == and <=> until the base
semantics of PHP comparisons are fixed and the necessary engine
prerequisite work is done.

I am working on such an RFC, as I frankly do not trust people to think
stuff through and handle things like polymorphic comparisons.

Also, introducing some new kind of weird operator is just... bad.

Best regards,

George P. Banyard