TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Union Types have been accepted for PHP 8

140 点作者 BafS超过 5 年前

9 条评论

yagodragon超过 5 年前
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 未加载
brenden2超过 5 年前
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 未加载
tylerjwilk00超过 5 年前
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 未加载
ilovecaching超过 5 年前
I wonder how stock PHP is stacking up to Hack both from the dimensions of efficiency, safety, and productivity these days.
评论 #21493600 未加载
评论 #21493698 未加载
Supermancho超过 5 年前
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 未加载
6gvONxR4sf7o超过 5 年前
This is cool! I wish tools like postgres had them too.
评论 #21493552 未加载
sedeki超过 5 年前
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 未加载
baby超过 5 年前
Now please do this for Golang :)
astrodev超过 5 年前
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.