One Minute With PHP6

18 comments | 16,939 views

php6PHP6 is the latest, yet unreleased version of PHP. It is still under development and won’t be released for some time yet. Nonetheless, it is still important that we consider the changes we know about at the moment, and write scripts which are compatible.

If you want to make use of PHP6 when it comes, you’re going to have to write your new scripts so they are compatible, and possibly change some of your existing scripts. To start making your scripts PHP6 compatible, I’ve compiled a list of tips to follow when scripting:

  1. FILE_BINARY and FILE_TEXT constants available for use with filesystem functions.
  2. register_globals will be gone.
  3. magic_quotes will also disappear.
  4. $HTTP_*_VARS has been removed, in favour for $_GET, $_POST, etc.
  5. ereg() no longer available in core PHP6.
  6. Initiating objects with the reference operator (& new Object()) will generate E_STRICT error.
  7. E_STRICT error messages are included in E_ALL errors.
  8. {} for string offsets no longer available.
  9. [] un-deprecated for accessing characters in a string.
  10. ASP-style tags can no longer be used.
  11. Better Unicode Support.
  12. var will be an alias of public, and raises E_STRICT warning.
  13. Support for 64 bit integers.
  14. With ternary operator, the “true” expression is no longer required – this can be done: $a = $s ?: ‘b’; (Not clear yet exactly how this will work).
  15. zend.ze1_compatibility_mode removed.
  16. safe_mode is being removed.
  17. Freetype1 and GD1 support removed.
  18. dl() is only enabled when a SAPI layers registers it explicitly.
  19. Support for dynamic break levels removed.
  20. XMLReader and XMLWriter will be in the core distribution.
  21. mime_magic removed from the core.
  22. Fileinfo moved to the core.
  23. ext/soap on by default.
  24. foreach supports multi-dimensional arrays: foreach($a as $b => list($c, $d))
  25. microtime() will return as float by default.
  26. opcode cache included in core distribution, but turned off by default.
  27. flags parameter available for file_get_contents().
  28. before_needle parameter added to strstr() – allows strstr() to return part of haystack before occurence of the needle.
  29. namespace, import, and goto become reserved words.
StumbleIt!
Comments

Hmmm its not PHP anymore.

--ReplyReply to this comment


PHP stopped being php when they turned off short-tags by default. It has got too enterprisy. We need need a new fresh PHP.

--ReplyReply to this comment


RE 111: I don’t understand what you mean by “it’s not PHP anymore”. Sure it is. I am a longtime PHP coder and welcome the continued evolution of the language. There is still a lot of work to be done, but these are some really great decisions in moving the language forward.

RE Habib: What do you mean exactly by “got too enterprisy”? I love php, but there are some very real short-comings of the language that make it less than optimal. I still use it every day, but also welcome the maturing the language has seen as more people become involved in its development and the planning of its progression.

I for one, am looking forward to PHP 6.

--ReplyReply to this comment


@Habib I agree with you. I don’t like the Java-style visibility modifiers.

--ReplyReply to this comment


Well.. first time view of this page was this:

http://burka.ormset.no/~oo/filedump/php6-20090301-161710.png

:D

--ReplyReply to this comment


I don’t know much about PHP but as I read down the list it looked like it was getting more Ruby/Rails-ish. They are getting rid of a lot of bad things (i.e. register_globals) so its not a bad thing. But it does kinda feel like your losing the spirit of PHP.

Just my .02$ worth.
Richard

--ReplyReply to this comment


@Mattle I absolutely agree with you about your opinion.

--ReplyReply to this comment


@Richard: Pardon me, but WTF does ditching register_globals have to do with Ruby and the Rails framework? Could you please send me a pair of those red-tinted glasses?

--ReplyReply to this comment


As a long-time PHP programmer – I’m confused why this is a major version release…

--ReplyReply to this comment


I am really looking forward to the new PHP, I think this is a step in the right direction.
A lot of people think that PHP should keep features that make it easy to use but the problem with this is that the same features that provide that functionality, also bring a lot of security holes to the language which makes PHP somewhat inferior to other enterprise level languages.
So far, PHP has been able to maintain a good mix of security, ease of use, and extensibility. Which is not easy to achieve!

Great summary by the way!

--ReplyReply to this comment


Re 14: With ternary operator, the “true” expression is no longer required – this can be done: $a = $s ?: ‘b’;

I believe this one would follow GCC semantics, i.e. “a ?: b” is the same as “a ? a : b” except that a is only evaluated once.

--ReplyReply to this comment


wonder why they bothered to add this into foreach

foreach supports multi-dimensional arrays: foreach($a as $b => list($c, $d))

instead of improving its performance

--ReplyReply to this comment


Sure, you can write scripts that are compatible, OR just use the Pear PHP_Compat Package. :)

--ReplyReply to this comment


If any of the above mentioned changes really screw you up you need to throw out your PHP4 books. Seriously this stuff is ancient. 1999 is calling and they want their code back. I bet you still use sessions for login auth.

And if you think this is Rails-ish, unplug and uninstall your Internets. A winning career @ Wal-Mart may be beckoning.

--ReplyReply to this comment


$a = 7;
$b = 5;

$x = ( $a -$b )?: ‘-1′; // returns $x = 2 ;

--ReplyReply to this comment


@habib short_open_tag is not disabled by default… nor is it planned to be.

Also, PHP 5.3 is a big release… people interested in PHP 6 should be taking a hard thoughtful look at 5.3.

--ReplyReply to this comment


PHP needs a lot to improve before it has to have a major release. It needs a compiler, needs namespacing, speed, consitency

--ReplyReply to this comment


This page doesn’t say it, but it is getting a compiler (APC will be built-in).

--ReplyReply to this comment


Leave a comment

(required)

(required)


Spam protection by WP Captcha-Free