Developing PHP 6 Applications?
Posted: Tue Jun 23, 2009 8:25 am
Hello,
Lately I've been looking into PHP 6 and what it has to offer. I am trying to find out things that a developer has to understand in order to support PHP 6. So far I have noticed that:
1) Unicode aware functions
In PHP 6, all functions are Unicode aware. This can lead to problems when you use functions in non-Unicode way like:
The function strlen() is Unicode aware, and will return the number of characters rather than the number of bytes. It's cool that you can finally count the string length with it, but people who have used it for other purposes like byte counting, their code will miserably fail. [1]
2) Character code point access
which could create problems with applications that deal with bytes. [1]
[1] I am not entirely sure, but is there a way to disable Unicode semantics? Also, as far as I know - the encoding used for functions is determined by the script encoding? Does this mean that if index.php is UTF-8 which includes binaryProcessor.php which is ASCII - the functions in binaryProcessor.php will not use UTF-8?
3) Namespaces
It seems that the separator for namespaces is going to be the stupid \ character. So, a class like
Would be accessed like
It would be great if we could just replace the class file when switching to PHP 6,
But thanks to the great namespace delimiter \, we must recode everything in our whole application:
All third-party extensions and code would need to adapt to this...
Do you think that it is impossible to program a complex program that works in both PHP 5 and 6? What kind of things are needed to be handled if you are to support both of them? If you support them both, what features of PHP 6 you can't use? Or should I and other developers just wait until PHP 6 is mainstream and switch to it = recode everything and ask potential 3rd party module writers to adapt, too?
All thoughts welcome.
Ah, it seems that you can easily define the encoding to use in a PHP file:
But the question is, what can you do if PHP 5 doesn't recognize the declare()?
So, how much do you care about PHP 6? Will you only move to PHP 6 and drop the support for PHP 5 when you see the appropriate time to do so?
One thing that I really would like to know is that when PHP 6 is out?! Next year? 2 years? 5 years? If it takes many years for it to come out, I can stop worrying right now and just concentrate on PHP 5.
Lately I've been looking into PHP 6 and what it has to offer. I am trying to find out things that a developer has to understand in order to support PHP 6. So far I have noticed that:
1) Unicode aware functions
In PHP 6, all functions are Unicode aware. This can lead to problems when you use functions in non-Unicode way like:
Code: Select all
echo strlen(file_get_contents('binary_file.bin')); // 32
echo filesize('binary_file.bin'); // 402) Character code point access
Code: Select all
$a = "??";
echo $a[1]; // will output ? - not the byte[1] I am not entirely sure, but is there a way to disable Unicode semantics? Also, as far as I know - the encoding used for functions is determined by the script encoding? Does this mean that if index.php is UTF-8 which includes binaryProcessor.php which is ASCII - the functions in binaryProcessor.php will not use UTF-8?
3) Namespaces
It seems that the separator for namespaces is going to be the stupid \ character. So, a class like
Code: Select all
class MyProgram
{
static function MyGlobalFunction() {}
}Code: Select all
MyProgram::MyGlobalFunction();Code: Select all
namespace MyProgram;
function MyGlobalFunction();Code: Select all
MyProgram\MyGlobalFunction();Do you think that it is impossible to program a complex program that works in both PHP 5 and 6? What kind of things are needed to be handled if you are to support both of them? If you support them both, what features of PHP 6 you can't use? Or should I and other developers just wait until PHP 6 is mainstream and switch to it = recode everything and ask potential 3rd party module writers to adapt, too?
All thoughts welcome.
Ah, it seems that you can easily define the encoding to use in a PHP file:
Code: Select all
<?php
declare(encoding="ASCII");
echo strlen("?"); // 3 (bytes)
declare(encoding="UTF-8");
echo strlen("?"); // 1 (character)
?>So, how much do you care about PHP 6? Will you only move to PHP 6 and drop the support for PHP 5 when you see the appropriate time to do so?
One thing that I really would like to know is that when PHP 6 is out?! Next year? 2 years? 5 years? If it takes many years for it to come out, I can stop worrying right now and just concentrate on PHP 5.