QRdvark.com

PHP 6 Preview Unicode Perhaps the greatest addition to PHP 6 will be the integration of unicode support. A runtime switch in php.ini will be provided to enable or disable Unicode semantics. This default will be set to "On". When the Unicode runtime switch is set to "Off" Unicode features will still be accessable. Two string type, binary and string will be available for use. This will mean filenames can also have UTF-16 characters in them also. A downside to Unicode is that the $string[] operator will not be effective as the Unicode implementation uses 2 or 4 bytes per character. This makes it impossible to guess string position. Much more work will be done in this arena, so features in PHP 6 may come and go. Unicode will stay, but the implementation may change. Register globals is gone register_globals() has had a dogged history and looked doomed from the outset. Poor coding practices in userland made application insecure. This was, in part, the catylist for the SUPER GLOBALS array. register_globals() is currently Off by default in preference of the SUPER GLOBALS and in PHP 6 we see it finally put to rest. Should PHP 6 encounter a register_globals setting, or when starting PHP it will throw an E_CORE_ERROR. Other functions that depend on register_globals will also disappear. These include session_register, session_unregister and session_is_registered. Magic quotes gone This feature has not been evil but has been tiresome for coders who have had to guess or work around issues related to wether this was turned On or Off in php.ini. So much in the same way as register_globals is being removed, magic_quotes will join it. Again an E_CORE_ERROR will will be thrown should a magic_quotes, magic_quotes_sybase or magic_quotes_gpc setting be detected. Safe mode support dropped Safe Mode is a feature that same GID/UID as the initiating script. This has cause much grief and so is joining the list of the features to be scrapped. Safe Mode sends the wrong message to coders and leads them to use this feature as a security measure. This is not what if was designed for and when detected now will throw an E_CORE_ERROR mentioning the use of open_basedir(). PCRE reigns PHP Currently supports two regex engines, PCRE and EREG. PHP 6 could see the addition of ICU also and this will make things rather crowded in regex land. PCRE has won the day and will see the demise of EREG as it is no longer bundled. An EREG extension may become avaialble but the core PCRE extension will not be allowed to be disabled. File Info Added PHP has no real mime detection. The mime_magic extention exists but is a little flakey and a FileInfo package is available in PECL. This will be moved to the core and enabled by default. This will see the demise of the mime_magic extension and good riddance. 64 bit integers The 32 bit model has long been a restriction for many coders and the addition of a 64 bit integer paves the way for code such as this:

<?php 

function checkNum($integer){ 

  if(!
IS_INT64($integer
    { 
    (
int64$integer
    } 
  return 
$integer

?>
GOTO This is perhaps the second most requested feature in PHP. It is also the second most feature people have asked to keep out of PHP. The addition of the JUMP model for GOTO has won the day and has been included. Up to date info on the shape this will take can be found at https://QRdvark.com/phpdev/GOTO-TO-GO!.html. Labelled breaks have been suggested that would look something like this..

<?php 
  
for ($i 0$i 9$i++) 
    { 
    if (
true
      { 
      break 
foo
      } 
    echo 
"this is never shown"
  
foo
    echo 
'Iteration: '.$i.'<br />'

?>
Parameter order consistency How often have you needed to look at the manual to find the order of parameters? Can you name, off the top of your head, the order of needle and haystack for in_array()? Are you sure??? This has been going on for too long and PHP 6 sets to put us on the road to continued insanity. The few internal functions such as array_search() and in_array() will remain the same. Name spaces The most hotly contested feature for PHP is namespaces. Many can live without them by simple prefixing, others need them so badly they have supplied their own patches. The situation seems to currently be an implementation that follows.. a "name space" keyword to be implemented that can be wrapped around a class definition with {}. This would add internally to the class names defined inside it separated by a separator.


<?php 
namespace spl
  class 
file  
    

    } 

?> 
This would result in the creation of a class "splfile": Exceptions Currently, PHP does not support exceptions for notices and warnings. This should be remedied, but it seems as an existing work around is plausible for these, no changes will be made. Consider this snippet:

<?php 
function myErrorHandler($errorType$message){ 

  if (
$errorType == E_NOTICE
    { 
    throw new 
Exception$message$errorType); 
    } 


  
set_error_handler('myErrorHandler'); 

  
/** 
  * 
  * Throws a notice 
  * 
  */ 
  
echo $new
?> 
Short tags Another feature many claim should never have been added in the first place but has progated un-fettered for years is the use of short tags with code such as this all over..

<?php 

  $var 
'foo'

?> 

Some text or other stuff here


<?=$var?> 

Some have suggested the use of other implentations such as



<?php=$var?> 
Others have suggested <script language="PHP"> The end result seems to be that <? will stay but <% will go. <?php= will not be considered. Wrap up This is a brief preview into PHP 6 and it should be remembered that all of this is developmental and may be changed or scrapped over night. It looks as though there is a lot of hard work happening behind the scenes and we hoping for great things with PHP as the language matures further