# Test for edge cases with __get and property access flags

- Thread: https://externals.io/message/44136
- Original archive: https://news-web.php.net/php.internals/44136
- Started by Stan Vassilev on 2009-06-03T20:48:53+00:00
- Messages: 5
- 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

---

## #44136 — Stan Vassilev — 2009-06-03T20:48:53+00:00

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

Hi,

I created a test that covers the current behavior of __get and access flags in some edge cases:
http://pastebin.com/d2ad892f5

Those are:

1. When a property is declared, but then unset via unset($this->foo), __get will be called.
2. When a property is declared private/protected, then unset and set again, it remains with the same access flags as originally declared (i.e. a private property remains private when set again).
3. When the caller tries to retrieve $object->foo, and foo is a private/protected member the caller has no access to, instead of an error, __get is called.

I'm not very sure the current behavior on item 3 is the best one (maybe error should be thrown regardless?), but freezing on either would be better than leaving it undefined :)

My request is that the behaviors tested here are either improved for correctness, or freezed as is. And then this test, or modified version of it, is added to the PHP source code to faciliate that. Thanks.

Regards, 
Stan Vassilev

---

## #44153 — Alexey Zakhlestin — 2009-06-04T07:12:46+00:00

URL: https://externals.io/message/44136#44153 · In reply to: #44136

2009/6/4 Stan Vassilev <sv_forums@fmethod.com>

>
> 3. When the caller tries to retrieve $object->foo, and foo is a
> private/protected member the caller has no access to, instead of an error,
> __get is called.
>
> I'm not very sure the current behavior on item 3 is the best one (maybe
> error should be thrown regardless?), but freezing on either would be better
> than leaving it undefined :)


I always thought that this is the supposed behaviour. I believe I even
relied on it in one of my projects



-- 
Alexey Zakhlestin
http://www.milkfarmsoft.com/

---

## #44177 — Stan Vassilev — 2009-06-05T12:58:50+00:00

URL: https://externals.io/message/44136#44177 · In reply to: #44153

3. When the caller tries to retrieve $object->foo, and foo is a private/protected member the caller has no access to, instead of an error, __get is called.

    I'm not very sure the current behavior on item 3 is the best one (maybe error should be thrown regardless?), but freezing on either would be better than leaving it undefined :)


  I always thought that this is the supposed behaviour. I believe I even relied on it in one of my projects 


Hi,

If the community wants it like it is, then I'm just fine with that: as long as the test is committed, so that it doesn't change overnight. Any volunteers :)?

Regards, 
Stan Vassilev

---

## #44178 — Eddie Drapkin — 2009-06-05T13:07:09+00:00

URL: https://externals.io/message/44136#44178 · In reply to: #44177

I thought this was the expected behaviour as well and I am quite sure that
I've used it in an experiment (all class members private and _get() output
escapes them) that failed pretty miserably.  But I did think this was the
expected behavior.  Perhaps it ought to throw an E_STRICT?



>
>
>    3. When the caller tries to retrieve $object->foo, and foo is a
> private/protected member the caller has no access to, instead of an error,
> __get is called.
>
>    I'm not very sure the current behavior on item 3 is the best one (maybe
> error should be thrown regardless?), but freezing on either would be better
> than leaving it undefined :)
>
>
>  I always thought that this is the supposed behaviour. I believe I even
> relied on it in one of my projects
>
>
> Hi,
>
> If the community wants it like it is, then I'm just fine with that: as long
> as the test is committed, so that it doesn't change overnight. Any
> volunteers :)?
>
> Regards,
> Stan Vassilev

---

## #44180 — John Mertic — 2009-06-05T14:10:08+00:00

URL: https://externals.io/message/44136#44180 · In reply to: #44177

Here's that test. I don't have commit rights to that area of CVS so 
someone will need to do it for me.

John Mertic
jmertic@php.net


>      3. When the caller tries to retrieve $object->foo, and foo is a private/protected member the caller has no access to, instead of an error, __get is called.
>
>      I'm not very sure the current behavior on item 3 is the best one (maybe error should be thrown regardless?), but freezing on either would be better than leaving it undefined :)
>
>
>    I always thought that this is the supposed behaviour. I believe I even relied on it in one of my projects
>
>
> Hi,
>
> If the community wants it like it is, then I'm just fine with that: as long as the test is committed, so that it doesn't change overnight. Any volunteers :)?
>
> Regards,
> Stan Vassilev
