« first day (5170 days earlier)   

11:53
\o
@MarkR wiki.php.net/rfc/private-classes-and-functions When you have time, some feedback would be great.
@IluTov Your timing is impeccable. I was just in my IDE wishing for this. I'll take a read
So as a basic mechanism I think what you've got it an ideal first step, basic mangling entirely self contained. My particular use case is a bit more complex, I am not sure if "private" classes would be the right word for it, but "auto-sub-namespaced classes based on filename" doesn't exactly roll off the tongue.
What you've got there is a perfect first step.
12:34
@IluTov Not sure if the reference to @internal is appropriate, given that @internal should generally be visible outside the current file.
In the class ATest { the second one should probably be called BTest (copy and paste error).
Other than that, no comments. I like it. Please ship it.
@TimWolla Yes, thanks!
@MarkR Right. Swift calls it fileprivate. I'd be happy with that if you are.
That said, another modifier begs the question: Do we add fileprivate to methods and so forth? It's potentially useless, but not nearly enough IMO. And then we have more modifiers that are only applicable in certain positions.
For classes the possible alternative would be subclasses, but that is likely less flexible and causes more issues for the parser and associated tools.
And probably also for autoloading semantics, depending on how exactly one would indicate a subclass vs a sub-namespace.
Well if we're talking purely about naming, in JS modules/TS everything is default internal unless given the export modifier, I would suggest something like 'local' but fileprivate would work too.
@TimWolla That, but it's also not clear if nested classes necessarily means not accessible from the outer scope.
12:50
Sub-classes would be nice for associated iterators. I believe that's a primary use-case in Java. But for most cases a Generator would just work.
I suspect that once this lands and we get around to upgrading it, I'd try building a reflection hack where it parsed the mangled name, extracted the file path, and stored it relative to some root directory, so it could be re-created without caring which file path it was stored on (CI vs prod servers)
Nested classes might solve my use-case a little bit better tbh, although it'd be great if we could define them after the class rather than in it java style
Note that many programming languages allow nesting classes, but that doesn't necessarily make them private. E.g. it can just alter their namespace. E.g. a Kind enum in a Ast.Node class might become Ast.Node.Kind, which is still usable from the outside. So it might have to be combined with private.
And as Tim mentioned, in PHP, this comes with some autoloading issues if the nested class is not actually private.
The autoloading issue is more due to the PSR standards than PHP itself, and those could be easily changed
@MarkR Yes and no. It could be fixed in two primary ways, scanning the entire project and building a map, or recursively looking at the parent of the namespace (e.g. Ast\Node\Kind first, then Ast\Node, then Ast. But both come with some limitations.
13:06
@IluTov I was thinking something more like borrowing the static namespace accessor and doing \Foo\Bar::Child1::Child2
That's not to say it couldn't be combined with private too, if the user wanted it
@MarkR This is actually ambiguous, and also looks a little confusing to my eyes. 3v4l.org/v1cru
Hmmm yeah it treating the string exactly like the class would throw a wrench into it. There's some options, but I'd think it best to stay away from re-using the namespace separator
It's problematic for autoloading, I agree, but `\` is what I would expect tbh.
I get where you're coming from it, and I see the distinct similarities between a namespace-namespace and class-contained namespace, but like you say it would cause issues with autoloading, especially as you'd then have 2 (or more depending on level of nesting) valid locations which is a tad odd.
That said, recursive loading of classes should be quite rare, and especially deeply nested ones. So in practice it might actually be ok. Maybe something to discuss with the Composer folks. This would open up the possibility for other things, such as sealed classes, or possibly simplify the design of ADTs.
13:20
The optimized classmap should take care of most of it, although I am not sure how widely used it is on non-containerised workloads
In particular, enum Option { case None; case Some($value); } could result in a class Option\Some, which would simplify matching, avoiding the necessity for pattern matching just to make this useful. In theory, we could even just use its constructor, i.e. new Option\Some(), which can also be imported, so shortened to new Some().
@IluTov I don't like that this works.
This should have at least one more pair of parentheses :-D
@TimWolla At least? :D
This is where having an actual element to represent a class would be handy xD
@IluTov var_dump((((\Foo\Bar::Child1)))::Child2); would be fine with me.
13:31
<?lisp
Clearly @ should only suppress deprecations, @@ also notices, @@@ for warnings and @@@@ for errors.
I'm glad we kept this possibility for the future.
13:59
I just realized fileprivate is wrong anyway. It's not just restricted to the current file, but also the current namesapce block. It's been a few months since I implemented this. If we consider a class a new namespace, private on a nested class would work in a logically consistent manner.
 
3 hours later…
16:39
@IluTov I don't fully understand the argumentation with nested classes in the RFC - for namespace visibility it does nothing. But what's the argumentation why file private classes should not just be replaced by nested classes?
'Just' is perhaps doing a lot in that statement as I would assume internal classes would be a much bigger project. I can see the value to private auto-mangled symbols, but internal classes + visibility modifiers on them are undoubtably more powerful (and would meet my use cases far better tbh)
 
1 hour later…
18:03
@bwoebi They are two separate features. You could argue standalone private classes shouldn't be allowed, but what's the point? Especially if standalone private functions are allowed.

« first day (5170 days earlier)