Hi!
> Actually it is a simplest case, where only a single information was
> considered. But you can expand it to something more complex, where
> currently you will need create a static method to copy the data, which
> is not a normalized way like cast could do.
You can always use anonymous functi
Hello!
> What's wrong with new Number(123)?
Actually it is a simplest case, where only a single information was
considered. But you can expand it to something more complex, where
currently you will need create a static method to copy the data, which is
not a normalized way like cast could do.
>
Hi!
> 1. Converting from A to B:
>
> $a = 123;
> $b = (Number) $a; // $b is now instanceof Number
>
> A instanceof Number will created based on $a value.
What's wrong with new Number(123)?
> 2. Reduce object type (I don't know the technical term):
>
> class A {}
> class B extends A {}
>
> $b
>
> Currently PHP supports generic castings like (string), (int), ... maybe is
> time to allow class castings like (ToClass) $fromObject?
I've proposed something similar a year ago:
https://externals.io/message/105332
My intention wasn't to create an object from a scalar, nor was it to limit
to