On Tue, Aug 10, 2021 at 12:55 PM Philip Hofstetter <
phofstet...@sensational.ch> wrote:

> Hello
>
> The following valid <= PHP 8.0 code that intends to make the $line property
> public  is a fatal error in 8.1
>
> class FooException extends Exception {
>     public $line;
> }
>
> However, the fixed code for 8.1:
>
> class FooException extends Exception {
>     public int $line;
> }
>
> Is a fatal error in <= 8.0
>
> Is there a way to create a class that makes the $line property public
> that’s compatible with all versions of PHP without requiring conditional
> declaration of the class?
>
>
Not sure exactly why you need to $line property public.
If you need to be able to read it, you can use __get.
If you also need to write it, as that also worked, you can also use __set.

So an example that offers the same interface/interaction possible would be:
https://3v4l.org/tHhEL#v8.0.9
https://3v4l.org/tHhEL/rfc#vgit.master

But of course, when you look at the object with reflection, or how var_dump
prints it, the property will still be protected.

Regards,
Alex

Reply via email to