what's new in php 5.3: volume one
Post on 10-May-2015
3.988 Views
Preview:
DESCRIPTION
TRANSCRIPT
What’s New in PHP 5.3
Johannes Schlüter
David Zülke
PHP Awesomeness History
0
25.000.000.000
50.000.000.000
75.000.000.000
100.000.000.000
PHP/FI PHP 3 PHP 4 PHP 5 PHP 5.1 PHP 5.2 PHP 5.3 PHP 6
1 10.000 100.000 1.000.000 1.500.000 2.000.000
75.000.000.000
100.000.000.000
Woot Level
PHP Awesomeness History, on a logarithmic scale
1
562
316.228
177.827.941
100.000.000.000
PHP/FI PHP 3 PHP 4 PHP 5 PHP 5.1 PHP 5.2 PHP 5.3 PHP 6
1
10.000100.000
1.000.000 1.500.000 2.000.000
75.000.000.000100.000.000.000
Woot Level
Volume One
Namespaces
Closures, Part One
Late Static Binding
Operators, Syntax, Magic Methods & Constants
New & Removed Extensions, BC
Windows Support
Volume Two
PHARClosures, Part TwoSPLStream ChangesDate and Time Handlingext/mysqlndext/intlgetopt, OpenSSL, php.iniPerformance/Internals/GC
What’s New in PHP 5.3Volume One
Name\SpacesBecause Underscores Are Not Enough
Namespaceable Elements
namespace Foo;const ANSWER = 42;class C { /* ... */ }function f() { }
echo Foo\ANSWER;new Foo\C();Foo\f();
Multiple Namespaces
namespace Foo { class C { /* ... */ }}namespace Bar { class C { /* ... */ }}
Namespaces Example #1
MyFramework/someModule/Foo.class.php:<?phpnamespace MyFramework\someModule;class Foo { /* ... */ }?>
app/Bar.class.php:<?phpclass Bar extends MyFramework\someModule\Foo { /* ... */ }?>
Namespaces Example #2
MyFramework/someModule/Foo.class.php:<?phpnamespace MyFramework\someModule;class Foo { /* ... */ }?>
MyFramework/someModule/Bar.class.php:<?phpnamespace MyFramework\someModule;class Bar extends Foo { /* ... */ }?>
Namespaces: call_user_func// it's a string, so we need to use a FQNcall_user_func_array( array( __NAMESPACE__.'\some_class', 'method' ), $params);
Class Resolutionnamespace MyFramework\someModule;class PdoException {}
new PdoException(); // MyFramework\myModulenew \PdoException(); // ext/pdo
new DateTime(); // class not found!new \DateTime(); // works
Function Resolutionnamespace MyFramework\someModule;function strlen($param) { return 0;}
echo strlen("hello world"); // 0
echo \strlen("hello world"); // 11echo some\other\space\strlen("hello world");
Using Namespaces
foo/bar.php:<?phpnamespace foo\bar;class class1 {} // foo\bar\class1?>
some/code.php:<?phpuse foo\bar;new bar\class1();?>
Aliasingfoo/bar.php:<?phpnamespace foo\bar;class class1 {} // foo\bar\class1?>
some/code.php:<?phpuse foo\bar as baz;use foo\bar\class1 as zomg;new baz\class2();new zomg();?>
ClosuresChapter One: The Basics
Closures: Very Basic$array = array(3, 9, 2);
array_filter( $array, function($element) { return $element > 5; });
Late Static Bindingohai, I’m in ur base, calling teh selfz
The ActiveRecord example
$user = User::findByID(23);
echo "Hello " . $user‐>getName() . "!\n";
$user‐>setPassword("verysecret");$user‐>save();
Implementation (w/ Injection)abstract class ActiveRecord { static function findById($id) { $table= get_called_class(); $query = "SELECT * FROM " . $table . " WHERE id=" . $id; /* .... */ }}
class User extends ActiveRecord {}class Entry extends ActiveRecord {}
$a = User::findById(2);$b = Entry::findById(4);
self vs static with LSBclass Base { public static function m() { self::printName(); static::printName(); }
static function printName() { echo __CLASS__; }}
Base::m();
BaseBase
self vs static with LSB
BaseExtended
class Extended extends Base { static function printName() { echo __CLASS__; }}
Operators, Syntax, Magic Methods & ConstantsAnd Exceptions That Eat Each Other
__callStatic()
class Foo { public static function __callStatic($name, $args) { echo $name; }}Foo::boats();
boats
Static Calls w/ $classname
$cls = 'DateTime';$cls::getLastErrors();
Constants in Global Scope
const EGG = 'bacon';
NOWDOC
echo <<<'BAI'Price: $US 375BAI;
Price: $US 375
HEREDOC
echo <<<"BAI"Price: $US 375BAI;
Notice: Undefined variable: US...
__DIR__
// old: function call, conditional includeinclude(dirname(__FILE__) . '/brother.php');
// new: magic constant, no conditional includeinclude(__DIR__ . '/brother.php');
Exception Linking
try { $pdoStatement‐>execute();} catch(PDOException $e) { $up = new RuntimeException('PDO fell over', 0, $e); throw $up; // lame joke, ain't it?}
Ifsetor
$id = $_GET["id"] ?: 0;
Notice: Undefined index: id
goto
label: durr;$i++;if($i < 100) { goto durr;}
New/Removed ExtensionsAnd Backwards Compatibility Changes
New Extensions
intl
sqlite3
mysqlnd
phar
fileinfo
enchant
Removed Extensions
msql
dbase
fbsql
fdf
ncurses
ming
sybase (-> sybase_ct)
Deprecated: ereg
Potential BC breaks
New Keywords:
namespace
goto
New global identifiers:
New extensions
New Closure class
zend.ze1_comptibility_mode
Parameter parsing: objects not interpreted as arrays anymore by these funcs:
current, next, key, each, reset, end
natsort, natcasesort, usort, uasort, uksort
array_flip, array_unique
call_user_func_array w/ refs
function foo(&$param) {}// breakscall_user_func_array("foo", array(23));// breakscall_user_func_array("foo", array($var));// workscall_user_func_array("foo", array(&$var));
E_DEPRECATED
New error level to indicated deprecated stuff scheduled for removal in later releases
Part of E_ALL
which is good :)
E_USER_DEPRECATED for userland errors
Should be used for deprecated stuff, so E_STRICT can be used for the intended “bad practice” purpose
WindowsMuch improved
BugfixesSome of which are really, really important
- Fixed bug #47757 (rename JPG to JPEG in phpinfo). (Pierre)
Thank You And Goodbye!Johannes Schlüter (johannes@php.net)
http://twitter.com/phperror
David Zülke (david.zuelke@bitextender.com)
http://twitter.com/dzuelke
top related