Live data from Hacker News

PHP 8.5

stitcher.io

141–150 of 197 posts

Re: PHP 8.5

#141

Earlier quoted context omitted.

Python managed to do this by not actually checking the types at runtime. If you declare a list[int] return type but you return a list[string] then nothing happens, you're expected to prevent that by running an offline typechecker. PHP chose to check types at runtime. To check that a value is really an array the runtime could have to loop through the entire array. All the types PHP currently implements are simple and…

Precisely. PHP has tools for this too, but lack the syntax. Right now you need to to all typings in comments, and thats just as bad as jsdoc was in 2005. This could be the way PHP could go, they just need the lexer to handle types, and not do any runtime checking at all. But i guess that goes against what the php devs want, but it sounds so wasteful, to typecheck the same code time after time even if it passed some s…

The current amount of typechecking might be a net efficiency improvement AFAIK. It provides a hard runtime guarantee that variables are certain types while Python has to check whether something is supported at the last possible moment. But I don't know how much use the optimizer makes of that.

Re: PHP 8.5

#142

Earlier quoted context omitted.

It has nothing to do with being “too hard”, and everything to do with not making sense to the type system. PHP is weakly-typed and heavily reflection-based (so everything is aware of it’s and each other’s type at all times). Adding generics to PHP would make CS fundamentalists somewhat happy, but do nothing to change the fundamental design of PHP nor offer any of the traditional benefits that generics offer to strong…

> And would be a massive headache to implement Exactly. The type system was never built for anything even slightly more complex. Its basically annotations for primitive types and classes. PHP has always had an weak type system, so adding generics will most likely never happen. > Adding generics to PHP would make CS fundamentalists somewhat happy PHP has really only one collection datatype (the infamous array), so hav…

PHP typing is most definitely stronger than python overall.

Yes array is the evil collection type of everything, but that's how it's meant to work. Array is the quick and dirty 'throw everything in there' thing. PHP has classes and they're very full featured and offer lots of type safety - use those.

Re: PHP 8.5

#143
post #63

Earlier quoted context omitted.

The web is not getting any simpler.

I don't see how making a language more complex can help with that. Complex languages makes sense for system programming where you want to squeeze some performance.

Making a language more complex often leads to simpler code. Keeping a language too simple often forces overly complex code.

Re: PHP 8.5

#144
post #7

PHP becomes a complex language with each update. For what reason? Its application is still limited to the web, mostly.

I downvoted you before reading the fine article. I'm back to correct that. The new array_first() and array_last() functions are nice, everything else is either reimplantation of existing features or "features"which will make maintainability more difficult. The pipe operator is one such example. I don't need it - these nested methods are not really an issue in any codebase I've seen. The new syntax only works for unar…

I don't understand how this is more bug prone. The nesting is a HUGE problem because it's extremely unreadable. The arrow is much more readable, and array functions are very simple too.

Re: PHP 8.5

#145
post #3

still remember been on #php with count down to php3 announcement

I remember the discussions at the time about which filename extension to use - and I can not believe that .php3 won. I think that I was the first to bring up the subject for PHP 4, to use .php again and not include the version number.

i still have phtml and php3 files somewhere in backups. used to run on php one of biggish local sites that you probably know

Re: PHP 8.5

#146

Earlier quoted context omitted.

> you cant return an typed array from a function, witch is just really bad. Why is it bad? In particular, why is it worse than not being able to declare a typed array in your current scope? (I understand the basic argument in favor of typed arrays, but I also understand why PHP would choose not to go that route; I'm not sure I see how it's worse to not be able to return one from a function, given that they don't exis…

I often return some collection of types in an array eg [User, Config]. Right now my return type is just "array". To get this to work i need to build yet another wrapper class and all that, and thats just wasteful and totally unnecessary. A even more simpler example is An array of some sort of Item. I cant return array(Item), but i only can return an array.

What do you mean, "to get this to work"? It's a PHP array. It will return whatever you need it to.

What is not working?

Re: PHP 8.5

#147

PHP's evolution since PHP 5 has been substantial, and I think this is a real problem. As someone who learned the language years ago, the pace of change (generics, attributes, match expressions, typed properties) makes modern codebases genuinely difficult to follow. I suspect this affects many developers who cut their teeth on PHP but haven't kept up. The language has become a different beast, which is a strength for…

I used laracasts.com plus AI code assistants to bring myself back up to speed pretty quickly.

Re: PHP 8.5

#148

PHP's evolution since PHP 5 has been substantial, and I think this is a real problem. As someone who learned the language years ago, the pace of change (generics, attributes, match expressions, typed properties) makes modern codebases genuinely difficult to follow. I suspect this affects many developers who cut their teeth on PHP but haven't kept up. The language has become a different beast, which is a strength for…

I work on projects from PHP 5.6-8.4 and I can't say it feels that different. It's mostly just type differences.

But PHP 5 was released 21 years ago and is unsupported. Companies using it are putting their customers at risk.

Re: PHP 8.5

#149
if they was something to learn it was for the Ruby community to learn from the PHP community on how to reinvent itself.

PHP like Ruby had some big companies built on it - Facebook: PHP, Ruby: Github/Shopify

PHP was able to swallow Hack and become PHP8 - they optimized for getting beginners into the language / ecosystem

Ruby while a beautiful / friendly language and ecosystem - got into political wars - didn't optimize for beginners on windows etc

even as a person who favors Rails - Laravel is ahead -> on documentation & bringing various ways to do things into the framework. There's no stick with Hotwire. You wanna do livewire go ahead, we will help you. You wanna do Inertia + JS - go ahead we will help you.

Re: PHP 8.5

#150
post #62

PHP should do a real major compatibility break and remove $ sigil from variable names. It's gonna be worth the pain!

I would love that. But yeah, it would probably kill PHP because it would break all code.

Maybe https://getrector.com could auto-fix 99% of code but it would still be very hard to get adoption.

Post reply on HN