# Multiple Visibility Level Getters/Setters

- Thread: https://externals.io/message/56419
- Original archive: https://news-web.php.net/php.internals/56419
- Started by Clint M Priest on 2011-11-19T01:46:09+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #56419 — Clint M Priest — 2011-11-19T01:46:09+00:00

URL: https://externals.io/message/56419#56419

What would everyone think about multiple levels of visibility for getters/setters?

class Sample {

public $Variable {
                public get { return "Public"; }
                protected get { return "Protected"; }
                private get { return "Private"; }

                public set { ... }
                private set { ... }
}
}

Whichever getter/setter would be called with the most restricted access, so externally public, internally protected (if inherited) or private from within.

Any value to this?  I can see some use cases and wouldn't be any more difficult to implement into what I'm already doing.

-Clint

---

## #56420 — Hannes Magnusson — 2011-11-19T02:15:46+00:00

URL: https://externals.io/message/56419#56420 · In reply to: #56419

> What would everyone think about multiple levels of visibility for getters/setters?
>
> class Sample {
>
> public $Variable {
>                public get { return "Public"; }
>                protected get { return "Protected"; }
>                private get { return "Private"; }
>
>                public set { ... }
>                private set { ... }
> }
> }

No please.
That will create a major WTF factor.

-Hannes

---

## #56433 — Michael Wallner — 2011-11-19T18:25:07+00:00

URL: https://externals.io/message/56419#56433 · In reply to: #56419

> What would everyone think about multiple levels of visibility for
> getters/setters?
> 
> class Sample {
> 
> public $Variable {
>                 public get { return "Public"; } protected get { return
>                 "Protected"; }
>                 private get { return "Private"; }
> 
>                 public set { ... }
>                 private set { ... }
> }
> }
> 

No. Don't. Ever.

Mike

---

## #56434 — Lars Strojny — 2011-11-19T19:45:43+00:00

URL: https://externals.io/message/56419#56434 · In reply to: #56419

Just throw an error if conflicting accessors are defined. In the case of subtypes: accessors may broaden the interface, but not limit it => LSP. So it’s fine to make a parents protected accessor public, but not the other way around.

Am 19.11.2011 um 02:46 schrieb Clint M Priest:

> What would everyone think about multiple levels of visibility for getters/setters?
> 
> class Sample {
> 
> public $Variable {
>                public get { return "Public"; }
>                protected get { return "Protected"; }
>                private get { return "Private"; }
> 
>                public set { ... }
>                private set { ... }
> }
> }
> 
> Whichever getter/setter would be called with the most restricted access, so externally public, internally protected (if inherited) or private from within.
> 
> Any value to this?  I can see some use cases and wouldn't be any more difficult to implement into what I'm already doing.
> 
> -Clint

---

## #56435 — Keloran — 2011-11-19T21:12:19+00:00

URL: https://externals.io/message/56419#56435 · In reply to: #56434

personally i think only public should be done with this method

all others should be follow the __set/__get method, since if you need
special rules, then they would be set-able by a public method



> Just throw an error if conflicting accessors are defined. In the case of
> subtypes: accessors may broaden the interface, but not limit it => LSP. So
> it’s fine to make a parents protected accessor public, but not the other
> way around.
>
> Am 19.11.2011 um 02:46 schrieb Clint M Priest:
>
> > […]
> getters/setters?
> > […]
> so externally public, internally protected (if inherited) or private from
> within.
> > […]
> difficult to implement into what I'm already doing.
> > […]

---

## #56436 — Clint M Priest — 2011-11-19T21:37:41+00:00

URL: https://externals.io/message/56419#56436 · In reply to: #56420

That would be a resounding no from everyone. :)

-----Original Message-----
From: Hannes Magnusson [mailto:hannes.magnusson@gmail.com] 
Sent: Friday, November 18, 2011 8:16 PM
To: Clint M Priest
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Multiple Visibility Level Getters/Setters


> What would everyone think about multiple levels of visibility for getters/setters?
>
> class Sample {
>
> public $Variable {
>                public get { return "Public"; }
>                protected get { return "Protected"; }
>                private get { return "Private"; }
>
>                public set { ... }
>                private set { ... }
> }
> }

No please.
That will create a major WTF factor.

-Hannes
