| ▲ | origini 8 hours ago |
| Ah boy o boy, PHP was the first lanuage I teached myself but man it still needs PHPDoc comment on return types? Come on PHP has so many shitty things, but even something basic like this is still not in the lanuage itself? |
|
| ▲ | pkkm 4 hours ago | parent | next [-] |
| PHP does have return type annotations. The reason the PHPDoc comments are needed here is that it lacks generics. Unfortunately, adding generics has proven problematic, but I still hope that we'll see them in the next few years. |
|
| ▲ | monster_truck 8 hours ago | parent | prev | next [-] |
| It's had return type declarations since 7. There's even intersection and literal types now. You could have typed this into google and it would have told you |
| |
| ▲ | origini 7 hours ago | parent | next [-] | | I did and it told me that it doesn't support typed arrays. | | | |
| ▲ | bakugo 7 hours ago | parent | prev [-] | | Type declarations are still quite limited, though. For example, you can declare that a function returns an array or a string, but not an array of strings. | | |
| ▲ | lofaszvanitt 6 hours ago | parent [-] | | Use a class if you need them. | | |
| ▲ | bakugo 6 hours ago | parent [-] | | How does that solve the problem? You can't declare an array of strings inside a class, either. | | |
| ▲ | eithed 3 hours ago | parent | next [-] | | You can annotate the method as `@return array<array-key,string>` or even `@return list<string>` (array of strings = indexed via anything that can be used as a key in PHP vs list of strings = indexed via incrementing integers, starting from 0). I guess the OP suggestion was to use Arrayable / Iterable interfaces, which would work as well, but would require more effort (= yes, declare a class) | |
| ▲ | lofaszvanitt 5 hours ago | parent | prev [-] | | Do some research :D. | | |
| ▲ | origini 5 hours ago | parent [-] | | Just to be clear, you suggest to wrap a typed array into its own class? is that the suggestion you think of? Because if yes, thats just ugly and a hack/workaround. |
|
|
|
|
|
|
| ▲ | Y-bar 8 hours ago | parent | prev | next [-] |
| TFA even shows examples of native return types. How could you not see that? |
| |
| ▲ | origini 7 hours ago | parent [-] | | The page itself shows plenty of examples were this is not true. Including generic type arrays which is not supported. |
|
|
| ▲ | throw1234567891 7 hours ago | parent | prev | next [-] |
| "Taught", not "teached". |
|
| ▲ | spiderfarmer 7 hours ago | parent | prev [-] |
| "Cool! A PHP article on HN, let's rehash some of my comments that got lots of upvotes 11 years ago!" |
| |
| ▲ | origini 7 hours ago | parent [-] | | Yepp, especially because not much changed and other languages did quite a lot. Strong contrast don't you think? | | |
| ▲ | wesammikhail 6 hours ago | parent [-] | | Hmmm not much changed you say... Lets take a look at https://wiki.php.net/rfc ooh wait, you couldn't be more wrong. Pikachuface.png | | |
| ▲ | origini 6 hours ago | parent [-] | | Core issues have not been fixed. You remember when HHVM / hack came out from Facebook? Besides the fact that it was quite a dick move from Facebook to bring it out and then stop supporting it, it pushed PHP to take performance temporarily serious and there was so much air in it. But the standard library is still inconsistent as hell, type system is still garbage especially mixxing strict and non strict. The concurrency implementation? Has to be fixed again by frameworks. And yeah i mean the critisism of my original comment stands as well and thats just an eye sore. |
|
|
|