Beruflich Dokumente
Kultur Dokumente
Released
End of Life
5.2
November 2006
January 2011
5.3
June 2009
July 2014
5.4
March 2012
September 2015
5.5
June 2013
June 2016
5.6
August 2014
August 2017
7.0
Q4 2015
Release + 3 months
Changes in PHP
Traits (5.5)
Traits are building blocks for classes
Traits can:
build on one another
be used together
are inherited by child classes
Traits
<?php
namespace Silex\Application;
use Monolog\Logger;
trait MonologTrait {
public function log($message,
array $context = array(),
$level = Logger::INFO) {
return $this['monolog']->addRecord($level,
$message, $context);
}
}
Traits
To use a trait:
<?php
use Silex\Application;
class MyApplication extends Application
{
use Application\MonologTrait;
$app->log("Something went wrong");
DateTimeImmutable (5.5)
<?php
$d1 = new DateTime();
print_r($d1);
$d1->add(new DateInterval('P4D'));
print_r($d1);
DateTime Object (
[date] => 2015-01-09 10:43:26
...
)
DateTime Object (
[date] => 2015-01-13 10:43:26
...
)
DateTimeImmutable
<?php
$d2 = new DateTimeImmutable();
print_r($d2);
$d2->add(new DateInterval('P4D'));
print_r($d2);
DateTime Object (
[date] => 2015-01-09 10:43:26
...
)
DateTime Object (
[date] => 2015-01-09 10:43:26
...
)
Output:
$2y$10$Q7Rm.Cmcu4lbvI7.C2q4Z.1LLoh4C63vBSfflQtfjs52GxhAc.s/G
$existing_hash = '$2y$10$Q7Rm.Cmcu4lbvI7.C2q4Z.1LLoh4C
$pass = "secretpassword";
if(password_verify($pass, $existing_hash))
echo "All good";
else
echo "Go away";
PHP Generators
Simpler than iterators - a function returning a
sequence of values.
<?php
$stuff = getValues();
foreach($stuff as $thing) {
echo $thing . "\n";
}
$email[] = "a@example.com";
$email[] = "Hi there";
$email[] = "Thanks for registering, hope you like it";
// old syntax
mail($email[0], $email[1], $email[2]);
//new syntax
mail(...$email);
Argument Unpacking
Let PHP unpack your args
Performance Comparison
How To Upgrade
Turn on E_DEPRECATED and watch the
logs of your existing platform
Use the PHPCompatibility PHPCS
standard
Compile new PHP and run test suite
Lint check with new version (php-l)
Run application with PHP's webserver
Upgrade a test/staging platform
Go for it!
Finding Platforms
New projects should be PHP 5.5 or later.
Questions to ask:
What versions of PHP are available?
Are backups included?
Which extensions are available, and
can I add others?
Can I get support with my PHP setup?