#IPC15 review - part II
Running PHP on NGINX – Tips and Tricks for High Performance Websites
by Harald Zeitlhofer
Surviving the next Upgrade
by Stefan Priebsch
How much does it cost
Frameworks spares you from reinventing solutions others already spent time and effort on implementing
At some point, however, a framework upgrade is in order
How can we take advantage of existing code, without coupling our code too tightly to the framework
Your app
Your app & dependencies
What changes?
Business requirements
APIs
Composer dependencies
- avoid them
- make them explicit
- Dependency Disguise as anti-pattern
Never ever rely on somebody else's interfaces
source http://code.tutsplus.com/
The Dependency Inversion Principle
Create Your own interface + adapter
Loose coupling works great if You are in charge of the interfaces
Composer Best Practices
by Jordi Boggiano
Five weird Tricks to become a better Developer
by Jordi Boggiano
Modernize your PHP Code
by Anna Filina
Closures
<?php
$input = array(1, 2, 3, 4, 5);
$output = array_filter($input, function ($v) {
return $v > 2;
});
$max_comparator = function ($v) {
return $v > 2;
};
$input = array(1, 2, 3, 4, 5);
$output = array_filter($input, $max_comparator);
Traits
<?php
trait MyTrait
{
public function doSomething($var)
{
return $var . ' does something';
}
}
class BaseController extends Controller
{
use MyTrait;
public function indexAction()
{
$this->doSomething('var');
}
}
Finally
<?php
function inverse($x)
{
if (!$x) {
throw new Exception('Division by zero.');
}
return 1 / $x;
}
try {
echo inverse(5);
} catch (Exception $e) {
echo 'Caught exception: ' . $e->getMessage();
} finally {
echo 'This is the last echo';
}
Short array syntax
<?php
$array = array(
'foo' => 'bar',
'bar' => 'foo'
);
// as of PHP 5.4
$array = [
'foo' => 'bar',
'bar' => 'foo'
];
Password functions
<?php
$hash = password_hash('rasmuslerdorf', PASSWORD_DEFAULT);
if (password_verify('rasmuslerdorf', $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
Foreach with list
<?php
$items = [
['a', 'b', 'c', 'd'],
[1, 2, 3, 4]
];
foreach ($items as list($var1, $var2, $var3, $var4)) {
//
}
Argument unpacking
<?php
function add($a, $b, $c)
{
return $a + $b + $c;
}
// a very simple call
add(1, 2, 6);
// as of PHP 5.6
$numbers = [1, 2, 3];
add(...$numbers);
Profiling with XHProf
by Ilia Alshanetsky
#IPC15 review II
By Jānis Šakars
#IPC15 review II
- 36