11 ms·
PHP 5.4.0 released
- function_seven 15y agoFrom here: http://www.php.net/manual/en/migration54.other.php http://www.php.net/manual/en/migration54.other.php > Chained string offsets - e.g. $a[0][0] where $a is a string - now work. Can someone explain why this is? I'm sure I'm misunderstanding, but this seems to mean that the following would work: $a = "Hello"; echo $a[0]; //"h" echo $a[0][0]; // also "h"?? What's the point? To avoid failure if I pass a string instead of a 2-dimensional array?
- fooyc 15y agoConsistency. Since $a[0] is a string, you would expect $a[0][0] to work too.
- function_seven 15y agoThanks. Let me rework my original question then. Why the hell didn't it always work? php > $a = "Hello"; php > echo $a[0]; H php > echo $a[0][0]; PHP Fatal error: Cannot use string offset as an array in php shell code on line 1
- tlack 15y agoPHP always seemed to have something weird in the parser about subscripts/array indexes. It's been there since I started using it during PHP3. Another similar fix they performed is making func()[0] work - before you had to do $tmp = func(); $tmp[0]. An old, old bug finally fixed.
- fooyc 15y agoClosures can now have a `$this` (by default it is the class in which the closure is declared). No more $that = $this hacks :)
- dave1010uk 15y agoThere's also Closure::bindTo() [0], which should allow you do do slightly more functional programming, like JavaScript's Function.apply() [1] [0] http://docs.php.net/manual/en/closure.bindto.php http://docs.php.net/manual/en/closure.bindto.php [1] https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply https://developer.mozilla.org/en/JavaScript/Reference/Global...
- TazeTSchnitzel 15y agoThey finally added short array syntax, removed register_globals and magic quotes, and the default character set is now UTF-8! This is good news indeed, they seem to be actually improving the language for once.
- rdoherty 15y agoAre there any benchmarks (synthetic or real-world) for the performance improvements? Would have been nice if the release notes had provided some.
- robryan 15y agoThere are some around like http://news.php.net/php.internals/57760 http://news.php.net/php.internals/57760, seen a couple more but forget where. The trend does seem to be towards far better performance across the board though which is good.
- 0x0 15y agoHere are the NEWS text: http://svn.php.net/viewvc/php/php-src/tags/php_5_4_0/NEWS?revision=323659&view=markup http://svn.php.net/viewvc/php/php-src/tags/php_5_4_0/NEWS?re... and the UPGRADING instructions: http://svn.php.net/viewvc/php/php-src/tags/php_5_4_0/UPGRADING?revision=323659&view=markup http://svn.php.net/viewvc/php/php-src/tags/php_5_4_0/UPGRADI...
- hinathan 15y agoI'm glad to see the short array syntax. Having strayed from PHP for a while to work on Ruby and JavaScript I'm really enjoying the ability to leave out semicolons in unambiguous end-of-line situations. Would love to see that make it into PHP at some point.
- deleted 15y ago[deleted]
- dirkdeman 15y agoIt took them long enough! In 2008 They voted 14/9 against short array syntax, even though a key user group voted 17/3 pro...
- chime 15y agoThe best part of short array syntax is that now you don't need named parameters to be supported by the language. function foo($opts) { echo $opts['source'] . $opts['destination']; } // just one extra pair of [] needed instead of new array() foo(['source' => '/123', 'destination' => '/abc']);
- Klinky 15y agoYou could do that before short syntax: foo(array('source' => '/123', 'destination' => '/abc')); Short syntax will make it less repetitive though. You can also use something like array_merge to emulate jQuery's $.extend for creating defaults.
- adorton 15y agoWhile I agree that it makes it easier to hack in that functionality, it would still be very useful to have named parameters for functions that don't implement that functionality. For example, fgetcsv takes parameters for delimiter, enclosure, and escape char (as of 5.3). Right now, if I want to specify a different enclosure, I'm forced to specify a delimiter even if I still want to use the default. I'd much prefer the ability to tell the function call that I want to override the enclosure and leave the delimiter alone.
- randomdrake 15y agoBig hitters: array dereferencing - $object->method()[$index] is now valid syntax built-in webserver via CLI - php -s - http://php.net/manual/en/features.commandline.webserver.php http://php.net/manual/en/features.commandline.webserver.php traits and the insteadof operator - http://php.net/language.oop5.traits.php http://php.net/language.oop5.traits.php shortened array syntax - $array = [1, 2, [1, 2, 3], 4]; Finally removed register_globals ;) Default charset of UTF-8! Read all about it! http://www.php.net/manual/en/migration54.php http://www.php.net/manual/en/migration54.php
- duskwuff 15y ago> Finally removed register_globals ;) They've also removed magic_quotes. A few functions that queried its status still exist, but you can't turn it on.
- smsm42 15y agoAlso it is faster and much better on memory consumption (depends on app of course, but 10-20% speedup and 20-30% less peak memory have been observed on some mainstream apps).
- blakeperdue 15y agoAre these numbers based on most previous versions of PHP? I'm on 5.3.10, do you think if I upgraded I would see similar improvements?
- tomcorrigan 15y agoIn a word: Yes. Of course, depending on your app YMMV!
- smsm42 15y agoYes, most probably you will see significant improvements. Of course, it depends on your app - if your app spends 99% of time in SQL database calls, PHP can do nothing about it. But PHP part would be faster and take less memory.
- 15y ago
- tlack 15y agoOther great little changes: - you can now do function()[0] - <?= always on despite what you say in the INI - safe_mode always off Seems like a return to sanity for the PHP team, at least temporarily.. I even kinda like the traits!
- klausa 15y agoHow is '<?=' being always on great change? I always thought it was weird and kind of stupid, but I'm genuinely curious how is that great thing. Also, Chained string offsets - e.g. $a[0][0] where $a is a string - now work. I have no idea how is that supposed to work. What should be the outcome on, say: $a = "foo"; $a[0][0] What about (assuming $a is still "foo"): $a[0][1] etc.?
- there 15y agoI always thought it was weird and kind of stupid, but I'm genuinely curious how is that great thing. How is it weird and stupid? <?php echo $var ?> is better than <?= $var ?> ?
- prodigal_erik 15y agoGood tools complain about <?= because it does not start with a named target. A lot of people just haven't read about the idea behind processing instruction syntax, which is also why we keep seeing mistakes like <%.
- danellis 15y agoA PHP script isn't an XML document, so processing instructions aren't really relevant. Even if your script is outputting XML, the script itself isn't going to be read by an XML parser.
- prodigal_erik 15y agoIt can if you want. It's not that hard to make documents which are valid before and after scripts run. This enables many more tools to work with them.
- dirkdeman 15y agoThey also improved the zend engine, CURL extension, added Tokyo cabinet abstract and Berkeley DB Support! Added a couple of hashes, Improved JSON Extension (JSON_NUMERIC_CHECK!) and a whole lot of bug fixes. The UTF-8 part was long overdue, glad they fixed that. I spend a lot of time programming in PHP. Its reputation is pretty bad, but updates like this keep me going!
- itmag 15y agoPHP was my first love (actually my second, after QBasic) when I was a teenager. Would love to get back into it now that it's a "real" language. Got any good tips about books on modern PHP programming?
- dirkdeman 15y agoBooks... not so much. I have another idea: you could check out an MVC-framework like codeigniter or CakePHP. There are numerous tutorials about them, and they give you the added benefit of working with an MVC pattern (knowledge you can use in other languages and frameworks as well, such as Ruby on Rails) and working Object Oriented. In my opinion, a big drawback of PHP is that it's so easy to screw up because it's easy to pick up. There are so many tutorials out there which will let you make a procedural, cross-scripted, sql-injected security liability spaghetti code... Starting with CodeIgniter or CakePHP is not very hard, especially when you have a little understanding on basic programming with PHP. Good luck!
- eropple 15y agoCodeIgniter and CakePHP are great examples of code badly brought forward into PHP5 from PHP4 roots. I wouldn't recommend either to either a novice or an expert; CodeIgniter is a fantastic example of out-of-date practices and CakePHP an example of writing such abjectly slow code that everybody else benchmarks against you to look good. If you're going to use PHP5, Symfony2 is a well-reasoned, best-of-breed system.
- latimer 15y ago
- emehrkay 15y agoAdded callable typehint. Nice
- roel_v 15y agoOh that's a nice one I hadn't noticed yet. Now all that's left is type hints for scalars...
- kijin 15y agoNow the question is, when will this become available in mainstream Linux distributions? I guess Arch et al. will get it pretty quickly, followed by Ubuntu 12.10 or maybe 13.04 depending on how many packages it affects. Good ol' Debian, on the other hand, might or might not get it in time for the Wheezy freeze. CentOS? Forgetaboutit.
- sanswork 15y agoYou mention two distros that are designed for stability. Thats very different from following the bleeding edge and they have their purpose and reason for it(Which while developers like myself and I assume you sometimes forget, our server admin friends never do). If you want to follow the leading edge there is always also the option of making your own packages.
- maratd 15y agoI use CentOS in my stack. It's going to get it today. Because I'm going to compile it =)
- saghul 15y agoYou may want to try DotDeb [1], they already have PHP 5.4 packaged for Debian :-) [1]: http://www.dotdeb.org/ http://www.dotdeb.org/
- Gigablah 15y agoThere's nothing stopping you from using, say, remi or webtatic repos on CentOS.
- pavelkaroukin 15y agoI see a lot of mentions of zend in extension names, function names.. Could someone elaborate how Zend relates to PHP?
- ayiteddybear 15y agomaybe this link can help: http://en.wikipedia.org/wiki/Zend_Engine http://en.wikipedia.org/wiki/Zend_Engine
- dirkdeman 15y agoZend developed the Zend Engine, a virtual machine. PHP4 is based on the Zend engine. Zend is more than just the framework, it literally is the core of PHP.
- bittarman 15y agoderp
- tobiasgies 15y agoZend Technologies Ltd. is a company started by Zeev Suraski and Andi Gutmans. The product of theirs you most likely heard of is Zend Framework, a PHP framework. It's however not their only product. Another one is the Zend Engine, which is a PHP interpeter and the virtual machine at the heart of PHP and the reason there are references to Zend all over the place.
- orthecreedence 15y agoThis is a nice list of improvements. As someone who spends a lot of the day in PHP-land, this is going to make me happy. As someone who also controls our entire server stack, waiting for someone else to decide to upgrade will not be a problem :) I'm glad the PHP devs are starting to actually make it a "real" language. It seems like PHP has always been the fat kid bumbling along behind everyone shouting "wait up guys!!" With closures in 5.3, syntax improvements and removal of horrible features (register_globals, magic_quotes, etc) in 5.4, it's shaping up quite nicely. Thanks, PHP devs!
- Pengwin 15y ago> waiting for someone else to decide to upgrade will not be a problem :) It is sad that a lot of servers are not like this, and PHP 5.4 will take ages to appear, if at all. Heck, I know of a hosting company still using PHP4.
- orthecreedence 15y agoFunny, I just had to deploy an existing site to a PHP4-only hosting environment. After a few hours of re-writing things I've been taking for granted (a lot of timezone code namely) everything worked fine. But yuck, I felt dirty afterwards.
- agildehaus 15y agoHosting company that still uses PHP4? Name names so we can avoid and chastise them!
- CptCodeMonkey 15y agoSeems like the multiyear unit-test coverage campaign is starting to pay off for the core PHP engineers, 5-6 years ago they swore they couldn't do shortened array syntax without major problems.
- sbarre 15y agoAlso awesome: "Arrays cast from SimpleXMLElement now always contain all nodes instead of just the first matching node. All SimpleXMLElement children are now always printed when using var_dump(), var_export() and print_r()."
- llgrrl_ 15y agoOne thing that's pretty important too is PHP-FPM. I've been dreaming about this for a long time for my nginx deployments. http://php-fpm.org/ http://php-fpm.org/
- chrisguitarguy 15y agoHasn't PHP-FPM been part of the PHP core for a while now? Since 5.3.3 (mid 2010) according the PHP FPM site.
- Mikushi 15y agoYes but has of 5.4 it is now considered stable, whereas before it was still experimental (even tho it worked fine).
- evilvoidhamster 15y agoThese features can only be good for PHP. Now the community needs to step up and care for the language better. We have seen the popularity of many languages and frameworks rise and fall, but php keeps chugging along. Modern frameworks are awesome, but the community is still rather fractured. I would love to see people more proud of php, to get over the fads around them. Now the language is getting some nice features, I think it's our time to shine :)
- mahmud 15y agoCan it add hex now? https://bugs.php.net/bug.php?id=61095 https://bugs.php.net/bug.php?id=61095
- greut 15y agothe ticket says Closed, so it better do.
- deleted 15y ago[deleted]
- CWIZO 15y agoWhen will this be available for FreeBSD? I really can't wait for traits, short array syntax and "foo()[0]". This is really a nice upgrade. Good job PHP team!
- jaequery 15y agoarray dereferencing - $object->method()[$index] is now valid syntax finally ....
- jaequery 15y agoshortened array syntax - $array = [1, 2, [1, 2, 3], 4]; ..... can't express how long i waited for these
- petdance 15y agoThey shipped it with 82 failing tests. http://gcov.php.net/viewer.php?version=PHP_5_4 http://gcov.php.net/viewer.php?version=PHP_5_4 Why even bother having a test suite?
- fruchtose 15y agoI'm not sure what's more worrying: * 82 failing tests * 44 expected test failures * 1119 compiler warnings I want to believe that PHP is growing up, but I have to admit I'm not convinced.