Live data from Hacker News

PHP 8

php.net

41–50 of 273 posts

Re: PHP 8

#41
post #37

Out of curiosity, why match expressions became popular for non functional languages? Without pattern matching on datatypes via cons expression (x::xs matching) it is just another kind of switch or if/else. Why do people promote this? here a nice comment on this topic: https://ocaml.org/learn/tutorials/data_types_and_matching.ht... "So one Really Cool Feature of functional languages is the ability to break apart data…

It simplifies the expression of if/then/elsif/elsif/else, even if it's not total.

Why not steal it?

Re: PHP 8

#43

Php was my first language I learned 15 years ago. On that way I really started to hate it because of all it's quirks. Many of those have been fixed and nowadays I really enjoy it again and it's my goto language for any web project. It really hits a pragmatic sweetspot. It's really easy to deploy and frameworks like symfony give you all the power like rails but without the magic.

What do you mean without the magic?

I think they mean stuff in Laravel framework and Ruby on Rails. Like database access where you can just use it as an object without worrying about queries and such. This is great, gets projects up fast.... until you need to do something different. It generally comes at the expense of flexibility.

Re: PHP 8

#44
post #37

Out of curiosity, why match expressions became popular for non functional languages? Without pattern matching on datatypes via cons expression (x::xs matching) it is just another kind of switch or if/else. Why do people promote this? here a nice comment on this topic: https://ocaml.org/learn/tutorials/data_types_and_matching.ht... "So one Really Cool Feature of functional languages is the ability to break apart data…

Pattern matching has been proposed in a separate RFC: https://wiki.php.net/rfc/pattern-matching

Re: PHP 8

#45
post #6

> 0 == 'foobar' // true That's PHP7 behaviour that's updated in 8 to return false. I'm not a PHP basher, I really like it these days, but why the heck was that example ever evaluating to true?

== is loose type. === is strict.

Is there any way to force the use of ===

Re: PHP 8

#46

Php was my first language I learned 15 years ago. On that way I really started to hate it because of all it's quirks. Many of those have been fixed and nowadays I really enjoy it again and it's my goto language for any web project. It really hits a pragmatic sweetspot. It's really easy to deploy and frameworks like symfony give you all the power like rails but without the magic.

I must be very picky, because to this day I still don't like it at all. It sucks less than it used to maybe, but if I compare it to other languages, I still would rather use anything else.

Curious if that's a general aversion to dynamic typing, or specifically PHP.

Re: PHP 8

#47

Earlier quoted context omitted.

In the absence of strict type checking it would be terrible, but == performs a loose comparison, and "foobar" cannot cast to any other number than 0. Perl will go about it the exact same way. Contrast this against strict comparison, "0" === 0 , which will evaluate as false.

Maybe "foobar" should evaluate to NaN.

Does PHP have separate int and float types? NaN is a float value and I would expect 0 to be an int.

Re: PHP 8

#48
How should one start learning with PHP these days?

My experience: hacked together a few PHP scripts over the years to notify me of a website change (5 minute cron job). Before that, I was a very good beginner with VB6 back in highschool.

There are a couple of ambitious database-driven website projects I would like to create, but I don't know where to start. I like the KISS philosophy, and I think PHP and MySQL would fill that. Is there an obvious alternative that I'm missing?

I was thinking of hoing through the w3schools PHP turtorial. Is there a better or more up-to-date resource?

Re: PHP 8

#49

Earlier quoted context omitted.

What do you mean without the magic?

Ruby is extreme flexible in terms of metaprogramming in rails uses that very much. And ruby is not statically typed. So if in rails you declare an active record model with belongs_to etc it's hard to keep track of what is really happening under the hood. In php you have almost no runtime metaprogramming so the things that could happen if you read a piece of code are reduced to a smaller set of options that are easier…

Ruby also raises an exception for a string coercion to an int when the string isn't an obvious int.

Re: PHP 8

#50
post #6

> 0 == 'foobar' // true That's PHP7 behaviour that's updated in 8 to return false. I'm not a PHP basher, I really like it these days, but why the heck was that example ever evaluating to true?

I'm kind of surprised they'd change a core language semantic, even in a major update... won't this make upgrading to PHP8 for a large codebase hard to do with confidence?

That was certainly a concern. When instrumenting PHP to detect where the behavior changes and testing various codebases, I found that this actually happens much more rarely than I would have anticipated in advance. We're talking like 2 occurrences in the test suite of major frameworks.
Post reply on HN