# ReflectionProperty::setValue() and ReflectionProperty::setAccessible()

- Thread: https://externals.io/message/41871
- Original archive: https://news-web.php.net/php.internals/41871
- Started by Sebastian Bergmann on 2008-11-12T19:29:05+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

---

## #41871 — Sebastian Bergmann — 2008-11-12T19:29:05+00:00

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

Currently ReflectionProperty::setValue() ignores the setting made by
 ReflectionProperty::setAccessible(). Is this intentional or was it just
 forgotten to handle ref->ignore_visibility in setValue()?

 For some code I am working on it would be really helpful if setValue()
 could optionally work with private and protected attributes.

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #41905 — Marcus Boerger — 2008-11-13T19:01:11+00:00

URL: https://externals.io/message/41871#41905 · In reply to: #41871

Hello Sebastian,

  allowing to read is more than enough. And ofr the record I did not like
  that at all. If you need to write to a private variable, then obviously
  your class design is wrong. And testing is no argument, as you can nicely
  design so that this is not necessary.

marcus

Wednesday, November 12, 2008, 8:29:05 PM, you wrote:

>  Currently ReflectionProperty::setValue() ignores the setting made by
>  ReflectionProperty::setAccessible(). Is this intentional or was it just
>  forgotten to handle ref->ignore_visibility in setValue()?

>  For some code I am working on it would be really helpful if setValue()
>  could optionally work with private and protected attributes.

> -- 
> Sebastian Bergmann                          http://sebastian-bergmann.de/
> GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69




Best regards,
 Marcus

---

## #41907 — Sebastian Bergmann — 2008-11-13T19:17:59+00:00

URL: https://externals.io/message/41871#41907 · In reply to: #41905

Marcus Boerger wrote:
> And testing is no argument, as you can nicely design so that this
> is not necessary.

 For once, testing is not the argument :-) But this is not the place to
 discuss what I would like to use this feature for.

 I do not see why we added setAccessible() for getValue() and not
 setValue() when do not actually need it for getValue() [1].

 --
 [1] http://www.derickrethans.nl/private_properties_exposed.php

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #42080 — Sebastian Bergmann — 2008-11-29T15:13:19+00:00

URL: https://externals.io/message/41871#42080 · In reply to: #41871

Sebastian Bergmann schrieb:
> Currently ReflectionProperty::setValue() ignores the setting made by
> ReflectionProperty::setAccessible(). Is this intentional or was it just
> forgotten to handle ref->ignore_visibility in setValue()?

 See http://bugs.php.net/bug.php?id=46718 for a patch that implements the
 missing functionality in ReflectionProperty::setValue().

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #42081 — Derick Rethans — 2008-11-29T15:19:48+00:00

URL: https://externals.io/message/41871#42081 · In reply to: #42080

> Sebastian Bergmann schrieb:
> > […]
> 
>  See http://bugs.php.net/bug.php?id=46718 for a patch that implements the
>  missing functionality in ReflectionProperty::setValue().

We shouldn't really modify test cases though, but just add new ones. 
Other than that it looks ok, and yes, I simply forgot about this when 
adding this.

Derick

-- 
HEAD before 5_3!: http://tinyurl.com/6d2esb
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org

---

## #42082 — Sebastian Bergmann — 2008-11-29T15:30:34+00:00

URL: https://externals.io/message/41871#42082 · In reply to: #42081

Derick Rethans schrieb:
> We shouldn't really modify test cases though, but just add new ones. 

 I only modified the existing test case because it contained dead code
 and looked a bit confusing to me when I first read it.

> Other than that it looks ok, and yes, I simply forgot about this when 
> adding this.

 Thanks!

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
