On Mon, 26 Aug 2024, at 11:43, Mike Schinkel wrote:
>> On Aug 26, 2024, at 3:28 AM, Rowan Tommins [IMSoP] <[email protected]> wrote:
>> I was responding to someone justifying anything and everything the proposal allows, because
>> Reflection already allows it. If the feature was "first class syntax to access private methods
>> of a class", I don't think it would be controversial to challenge it. Saying
>> "Reflection can already do it" would be a poor defence, because part of Reflection's
>> job is to break the normal rules of the language.
>
> But saying that we can be certain default values are private and we
> want to keep them that way is provably false by the existence of
> Reflection.
Sorry to double-reply when the thread is already quite busy, but I overlooked this sentence, and
don't want to leave it unchallenged.
By this reasoning, any property or method marked "private" is actually part of the public
API of a class, because it can be accessed via Reflection. Perhaps we could add a "sudo"
operator to make it easier:
class Xkcd149 {
private function make_me_a_sandwich() { ... }
}
echo (new Xkcd149)->make_me_a_sandwich(); // error
echo (new Xkcd149)->(sudo)make_me_a_sandwich(); // OK, here you go...
I'd be surprised if anyone thought that was a good idea, because people are generally quite
happy to separate "is part of the language" from "is possible to do if you mess
around with Reflection APIs".
Right now, accessing the default value of an optional parameter is in the "possible if you mess
around with Reflection APIs" set; maybe we do want to move it to the "is part of the
language" set, maybe we don't; but claiming there is no distinction is nonsense.
---
Rowan Tommins
[IMSoP]