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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Short array syntax finally in PHP 5.4

110 点作者 harisenbon将近 14 年前

15 条评论

gdulli将近 14 年前
My big complaint about arrays wasn't declaring them. It was the endless array functions you have to use afterwards.<p>array_push<p>array_pop<p>array_slice<p>array_shift<p>array_unshift<p>array_map<p>array_key_exists<p>It kind of feels like they missed the point, saving 5 characters when you declare the array once, ignoring all of the other operations you do afterwards.<p>And this RFC, simple as it is, took 3.5 years to come to fruition.
评论 #2799602 未加载
评论 #2800212 未加载
评论 #2801330 未加载
评论 #2800071 未加载
评论 #2806951 未加载
评论 #2799590 未加载
评论 #2799558 未加载
nbpoole将近 14 年前
With the removal of bad legacy features like register_globals, magic_quotes_gpc, and safe_mode combined with new features like array de-referencing and traits, I'm really excited for PHP 5.4. :)<p>For anyone who's curious, here's a list of the changes in 5.4 alpha 1: <a href="http://www.php.net/releases/NEWS_5_4_0_alpha1.txt" rel="nofollow">http://www.php.net/releases/NEWS_5_4_0_alpha1.txt</a>
barredo将近 14 年前
Now if only when a function returns an array we needn't a variable...<p><pre><code> function boo(){ return array(1,2,3) } echo boo()[1];</code></pre>
评论 #2799433 未加载
评论 #2799436 未加载
评论 #2799431 未加载
评论 #2800582 未加载
viraptor将近 14 年前
Just looked through the RFCs... and I'm a bit surprised noone proposed unification of types yet. It seems a bit silly that the resources, objects, arrays, strings are different types at the language level. They could throw out / reorganise a lot of the randomly named functions this way. Just add the proper methods to the actual types and sort out the (haystack, needle) order, underscores or lack of them, etc.
评论 #2800403 未加载
Udo将近 14 年前
That's great news, finally we can do<p><pre><code> $a = [1, 2, 3]; </code></pre> and it also will make function calls with named parameters much more readable.<p>Sadly, it will be years before the majority of hosting providers adopt 5.4...
评论 #2799386 未加载
评论 #2801806 未加载
Tharkun将近 14 年前
Still strikes me as a useless bit of syntactic sugar. Is it <i>really</i> that much work to write array('foo' =&#62; 'bar')? As far as I can tell, writing ['foo' =&#62; 'bar'] isn't that much shorter in the first place.<p><i>sigh</i> Can the PHP devs focus on the real problems now? <i>cough</i> Unicode anyone? Ridiculously inconsistent naming of string and array functions? The woefully incomplete and useless STL? The lack of OO in arrays and strings?
评论 #2800771 未加载
评论 #2800138 未加载
评论 #2801756 未加载
评论 #2800108 未加载
snorkel将近 14 年前
My complaint about arrays in PHP is warnings for reading a array member that may not exist, such as when reading a form input that might not be there.<p><pre><code> $foo = $_POST["foo"]; </code></pre> Undefined array key! Oh, no! Tragedy! A crime has been committed! Are you kidding? Just set $foo to undefined and let me deal with the consequences, please?
评论 #2801274 未加载
评论 #2801375 未加载
评论 #2801871 未加载
评论 #2801289 未加载
评论 #2802517 未加载
MattBearman将近 14 年前
That's good to see, but like many have said, I'd really like to see proper OO stuff like $myArray-&#62;pop();<p>What about short object declaration syntax:<p>$obj = { param:'blah' };<p>PHP already has stdClass, so I doubt it would take much of a parser change to implement that.
thesmartace将近 14 年前
While I don't use PHP any more, this is still a massive improvement for those that do. Next on the list: Array and String literals as proper objects!
schiptsov将近 14 年前
"Perfection is achieved not when there is nothing more to add, but when there is nothing more to cut off."<p>Adding fancy syntax does not magically transform that crapware to something almost perfect like python3 or ruby (in its way) where these syntactic forms are among foundations of the language and are supported through all basic idioms. ^_^
snomad将近 14 年前
Looks like they decided NOT to include the scalar type hint. <a href="https://wiki.php.net/todo/php54" rel="nofollow">https://wiki.php.net/todo/php54</a><p>Even better would be bool/float/int/string/func ref type hinting...
agotterer将近 14 年前
What's the release roadmap and dates for 5.4?
评论 #2799532 未加载
Luyt将近 14 年前
$I $wish $they $would $get $rid $of $prefixing $every $variable $with $a $dollar $sign.
jrockway将近 14 年前
So does =&#62; quote the lhs, like Perl? Otherwise, what's the point?
评论 #2801757 未加载
ck2将近 14 年前
But PHP isn't a transmitted language like javascript, why even bother? It will only make the parser slower?
评论 #2799583 未加载
评论 #2800264 未加载
评论 #2800227 未加载
评论 #2799654 未加载