TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Union Types have been accepted for PHP 8

140 pointsby BafSover 5 years ago

9 comments

yagodragonover 5 years ago
When I started programming a few years back, I was told that PHP is legacy tech and a terrible language I should avoid like a plague. After years of battling with Node.js on the backend, I took a closer look at modern PHP and the Laravel framework and I was amazed by how good the developer experience was. The language itself feels like a lite version of Java. I believe everyone starting on web development should know PHP. It's hugely deployed, it has a very mature and rich ecosystem and it's a great language to build your side project/business without spending your time on meaningless tasks. Don't be driven by FOMO like I was, there's no such thing as a "perfect programming language". Every language has it's quirks and that's fine. PHP might be old and boring but it helps you get things done faster than using the new coolest language.
评论 #21494689 未加载
评论 #21494676 未加载
评论 #21494563 未加载
评论 #21496641 未加载
评论 #21496130 未加载
brenden2over 5 years ago
Whether you love it or hate it, it's cool that the PHP project has come so far. I know a lot of people still use PHP every day, so it's good to see the language continues to improve. I imagine a significant percentage of web services are still PHP based to this day.
评论 #21493547 未加载
评论 #21494178 未加载
tylerjwilk00over 5 years ago
It's nice to start out typeless during problem domain discovery and proof of concept phase then quickly introduce types when you better understand the problem. This change will help that phase transition with enforcement right in the runtime as opposed to simple doc block annotations.
评论 #21495753 未加载
评论 #21494924 未加载
ilovecachingover 5 years ago
I wonder how stock PHP is stacking up to Hack both from the dimensions of efficiency, safety, and productivity these days.
评论 #21493600 未加载
评论 #21493698 未加载
Supermanchoover 5 years ago
This is one bad feature among many good decisions, but bad nonetheless. The language will have yet-another-way to do type-erasure&#x2F;autoboxing that will have to be tracked down, in the interest of removing boilerplate when multiple types are desired to be coerced. Type safety is recognized as valuable by the PHP core voters on one hand, and waved away by the other.<p>Imagine the fun!<p>&lt;?php<p>function callit(float $numI) {<p><pre><code> $numB = $numI || ($numI&#x2F;2); echo gettype($numB).&quot;\n&quot;; $numF = ($numI&#x2F;2); echo gettype($numF).&quot;\n&quot;; return some($numB); </code></pre> }<p>function someType(int|float $numX):int {<p><pre><code> echo gettype($numX).&quot;\n&quot;; return $numX; </code></pre> }<p>$ret = callit(2);<p>echo gettype($ret).&quot;\n&quot;;
评论 #21496584 未加载
6gvONxR4sf7oover 5 years ago
This is cool! I wish tools like postgres had them too.
评论 #21493552 未加载
sedekiover 5 years ago
It was long ago I worked with PHP, before PHP 5. Is typing enforced with PHP these days? Or is it more like type hints, as in Python?
评论 #21493383 未加载
评论 #21493200 未加载
babyover 5 years ago
Now please do this for Golang :)
astrodevover 5 years ago
Before the usual avalanche of posts criticising some PHP 4 features, the union types look like a nice way to formalise something that is commonly used and very useful.