- Can someone smarter than me explain what they mean by "reified generics", "erased generics", and a use case for when to use one over the other?by tobinfekkes - 10 hours ago
- I may be missing something about how the PHP compiler/interpreter works, but I don't quite understand why this is apparently feasible to implement:by twiss - 9 hours ago
but the following would be very hard:class BlogPostRepository extends BaseRepository<BlogPost> { ... } $repo = new BlogPostRepository();
They write that the latter would need runtime support, instead of only compile time support. But why couldn't the latter be (compile time) syntactic sugar for the former, so to speak?$repo = new Repository<BlogPost>();
(As long as you don't allow the generic parameter to be dynamic / unknown at compile time, of course.)
- In the sense of an affirmative vote, the proper word is "yea."by SoftTalker - 8 hours ago
- write PHP a lot. every day.by calvinmorrison - 8 hours ago
I wish we had typed arrays. Totally not gonna happen, theres been RFCs but I have enough boilerplate classes that are like
Class Option Class Options implements Iterator, countable, etc.
Options[0], Options[1], Options[2]
or Options->getOption('some.option.something');
A lot of wrapper stuff like that is semi tedious, the implementation can vary wildly.
Also because a lot of times in php you start with a generic array and decide you need structure around it so you implement a class, then you need an array of class,
Not to mention a bunch of WSDLs that autogenerate ArrayOfString classes...
- In Hack, collection objects were one of the biggest early mistakes that the took a huge amount of effort to undo. It turns out that the copy-on-write semantics of PHP array were extremely important for performance and good APIs. Being able to pass arrays to things without fear of mutation allowed for tons of optimizations and not needing to copy things just in case. This is why Hack switched to using `dict`, `vec`, and `keyset` rather than collection objects.by yuliyp - 6 hours ago
More generally, it's weird to see a whole blog post about generics for PHP not even mentioning Hack's generics designs. A lot of thought and iteration went into this like 5-10 years ago.
See https://docs.hhvm.com/hack/arrays-and-collections/object-col... and https://docs.hhvm.com/hack/arrays-and-collections/vec-keyset...
- I am not much of a programmer so I was trying to figure out what generics are. And I am sure they are great, but my inner gremlin goes in sarcastic tone "we want these elaborate type systems, but we also want typeless because that is far more convenient to use, so we invented generics, a method to untype your type system"by somat - 4 hours ago
But really while I was reading up on what generics are I went, isn't that just python, strongly typed but your functions don't have built in type checks.
- The introduction to me reads as very confused:by noelwelsh - 2 hours ago
One of the most sought-after features for PHP is Generics: The ability to have a type that takes another type as a parameter. It's a feature found in most compiled languages by now, but implementing generics in an interpreted language like PHP, where all the type checking would have to be done at runtime, has always proven Really Really Hard(tm), Really Really Slow(tm), or both.
* The topic of the article is implementing generics at compile time, but this claims that PHP is not compiled.
* Type checking is orthogonal to compilation vs interpreter.
* Types are not checked at runtime. It is kinda the point of types that they are checked before code runs. Runtime checks are on values. You can reify types at runtime but this breaks a useful property of generics (parametricity) and it prevents the very useful feature of types without a runtime representation (often known as newtypes).
* If you want to use types in the colloquial "dynamic type" meaning as tags on values, and you also want to talk about generics (a feature that only makes sense for types-as-compile-time-properties) you need to be really careful in your terminology or confusion will abound!
- Nay, enough of complexity as it is, for now.by johnisgood - 2 hours ago
- So, PHP started off as a loosely typed language, then got types... and now they want to implement generics to have more loosely typed code? But as I understand it, types are still optional, so you can still use untyped variables for "generic" code? I'm probably missing something here, is it because of performance concerns? Or the edge case of absolutely wanting strongly typed PHP throughout (except for the part where they want generics)?by rob74 - 33 minutes ago