Anonymous Classes
class Post { use Loggable; }
$post = new Post;
Slide 56
Slide 56 text
Anonymous Classes
class Post { use Loggable; }
$post = new Post;
$post->setLogger(
new class implements Logger {
public function log($msg) {
echo date('m/d G:i') . ': ' .$msg;
}
});
Slide 57
Slide 57 text
Anonymous Classes
$postModel = new Post;
$myPost = $postModel->get(1);
//output = ‘09/08 16:20: Getting post 1’
Types
declare(strict_types=1);
function addNums(float $a, float $b) {
return $a + $b;
}
addNums(2, "1 week");
// Fatal error: Uncaught TypeError:
Argument 2 passed to addNums() must
be of the type float, string given
Slide 67
Slide 67 text
Types
function addNums(float $a, float $b)
addNums(2, "1 week”);
// Fatal error: Uncaught TypeError:
Argument 2 passed to addNums()
must be of the type float, string given
Types
class/interface
array
callable
bool
float
int
string
object
Slide 71
Slide 71 text
Return Type
Declarations
Slide 72
Slide 72 text
Types
function addNums(float $a, float $b) : int {
return $a + $b;
}
Slide 73
Slide 73 text
Types
function addNums(float $a, float $b) : int {
return $a + $b;
}
Slide 74
Slide 74 text
Types
function addNums($a, $b) : int {
return $a + $b;
}
addNums(1.5, 1);
// Fatal error: Uncaught TypeError: Return value of
addNums() must be of the type integer, float
returned
Slide 75
Slide 75 text
Types
function addNums(float $a, ?float $b) : int {
return $a + $b??0;
}
addNums(1, null);
// int(1)
Built-in Server
$ php -S localhost:8000
PHP 5.7.0 Development Server started…
Listening on localhost:8000
Document root is /home/ben/htdocs
Press Ctrl-C to quit
Slide 115
Slide 115 text
Composer
Slide 116
Slide 116 text
Another
Package Manager!?
Slide 117
Slide 117 text
Composer
Sane Package
Management
Autoloading via PSR4
Composer
$client =
new Services_Twilio($sid, $tkn);
$client->account
->messages
->sendMessage(…)
Slide 124
Slide 124 text
Unit Testing
Slide 125
Slide 125 text
No content
Slide 126
Slide 126 text
Unit Testing
PHPUnit
Behat
Mink
Selenium
CodeCeption
PHPSpec
Slide 127
Slide 127 text
Unit Testing
class ApiAuthTest extends PHPUnit_Framework_TestCase {
public function testVerify() {
$auth = new apiAuth();
$this->assertTrue($auth->verify());
Slide 128
Slide 128 text
Unit Testing
class ApiAuthTest extends PHPUnit_Framework_TestCase {
public function testVerify() {
$auth = new apiAuth();
$this->assertTrue($auth->verify());
Slide 129
Slide 129 text
Unit Testing
$ phpunit tests
PHPUnit 3.3.17 by Sebastian Bergmann.
Time: 0.01 seconds
OK (1 tests, 1 assertions)
Slide 130
Slide 130 text
Standards
Slide 131
Slide 131 text
No content
Slide 132
Slide 132 text
Standards
PHP-FIG
Framework
Interop
Group
Slide 133
Slide 133 text
Standards
Member Projects
Zend
Symfony
CakePHP
Magento
Joomla
Drupal
Slide 134
Slide 134 text
Standards
PSRs
PHP
Standards
Recommendation
Slide 135
Slide 135 text
Standards
PSRs
Autoloading
Interfaces
Style Guides