Re: Class cast
| From: | Stanislav Malyshev | Date: | Wed, 25 Mar 2020 23:06:09 +0000 |
| Subject: | Re: Class cast | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109314@lists.php.net to get a copy of this message | ||
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 = new B;
> $a = (A) $b;
>
> $a still is $b, but with "limited" access to A methods and properties.
Not sure why would you want to do this? What's the use case?
--
Stas Malyshev
smalyshev@gmail.com