Friday 27 May 2011

New Features in PHP 6.0 (and a few things about 5.3)


Unicode!!!!


• True support for Unicode (UTF-8) in PHP 6
• Can be disabled on per server basis


Caching
• APC (Alternative PHP Cache) moved to the core.
• Written by Rasmus
• Both page level (opcode) and application caching.


namespaces
• Namespaces are in PHP 6 and 5.3
• “namespace X::Y::Z” means all new class/function/
method names are prefixed with X::Y::Z class/
function/methods are resolved first against X::Y::Z.
• “import X::Y::Z as Foo” aliases the prefix “Foo” to
actually mean “X::Y::Z”



Late static binding
• In both 6.0 and 5.3
• See http://blog.felho.hu/what-is-new-in-php-53-part-2-late-static-binding.html
<?php
class ActiveRecord
{
public static function findByPk($id)
{
$calledClass = get_called_class();
// The magic happens here
}

}

class Blog extends ActiveRecord {}
Blog::findByPk(1);
?>




mysqlnd
• MySQL database driver written in the Zend Engine (nd == ‘native driver’)
• faster execution
• lower memory usage
• performance statistics
• client side cache (not ready for 5.3)
• Works with ext/mysql, ext/mysqli, PDO/mysql
• Available in 6.0 and 5.3



Breaking to a label
• similar to “goto”
• Can jump to a labeled point further down
the execution path.
<?php
for ($i = 0; $i < 9; $i++)
{
if (true) {
break blah;
}
echo "not shown";
blah:
echo "iteration $i\n";
}
?>



Foreach on Multidimensional  arrays
• syntactic sugar
<?php
$a = array(
array(1, 2),
array(3, 4)
);
foreach( $a as $k => list($a, $b)) {
// blah
}
?>




Improvements to []
• For both strings and arrays, the [] operator will support substr()/array_slice() functionality.
• [2,3] is elements (or characters) 2, 3, 4
• [2,] is elements (or characters) 2 to the end
• [,2] is elements (or characters) 0, 1, 2
• [,-2] is from the start until the last two elements in the array/string
• [-3,2] this is the same as substr and array_slice()
• [,] doesn't work on the left side of an equation (but does on the right side)


Microtime
• microtime returns a full float instead of
“timestamp microtime”
• Just like calling microtime(true)


Removed Features
• register globals
• magic quotes
• safe mode
• ereg removed from the core
• long variables (i.e. $HTTP_*_VARS)
• <%









No comments:

Post a Comment

Note: only a member of this blog may post a comment.