[presentations] master: Fixes
[email protected] (Rasmus Lerdorf) Tue, 6 Dec 2022 21:46:55 +0000
| Newsgroups | php.pres |
|---|---|
| Message-ID | <[email protected]> |
Author: Rasmus Lerdorf (rlerdorf)
Date: 2022-12-06T15:35:26-06:00
Commit: https://github.com/php/presentations/commit/ffafa7b7b21a45e5fd8bfb643445976488d3cfb9
Raw diff: https://github.com/php/presentations/commit/ffafa7b7b21a45e5fd8bfb643445976488d3cfb9.diff
Fixes
Changed paths:
M etsymex22.html
M slides/intro/php81_2021.xml
Diff:
diff --git a/etsymex22.html b/etsymex22.html
index 2fd33d6e..95b9b68d 100644
--- a/etsymex22.html
+++ b/etsymex22.html
@@ -190,7 +190,7 @@ <h3>Dec.7, 2022</h3>
</section>
<section id="etsyfw2" >
<p class="p" style="font-size:1.4em;text-align:left;">awesome.php</p>
- <pre><code class="php" data-trim style="font-size:1em;" >require 'bootstrap.php';
+ <pre><code class="php" data-trim style="font-size:1em;" >require 'bootstrap.php';
$request = HTTP_Request::getInstance();
$response = HTTP_Response::getInstance();
$controller = new Awesome_Controller();
@@ -203,13 +203,13 @@ <h3>Dec.7, 2022</h3>
<p class="p" style="font-size:1.4em;text-align:left;">Code/Awesome/Controller.php</p>
<pre><code class="php" data-trim style="font-size:1em;" >class Awesome_Controller extends Controller_Base {
public function doCoolThings($request, $response) {
- $id = $request->getGet('id', 0);
+ $id = $request->getGet('id', 0);
if (!$id) {
$response->redirect_error(Constants::ERROR_NOT_FOUND);
return;
}
- $thing = EtsyORM::getFinder('Thing')->findById($id);
- $stuff = Api::endpoint('AwesomeStuff', [$thing->id, 'max'=>10]);
+ $thing = EtsyORM::getFinder('Thing')->findById($id);
+ $stuff = Api::endpoint('AwesomeStuff', [$thing->id, 'max'=>10]);
$this->renderViewTree(New Awesome_View($thing, $stuff));
}
}</code></pre>
@@ -229,12 +229,12 @@ <h3>Dec.7, 2022</h3>
$this->stuff = $stuff;
}
public function getCssFiles(): array {
- return [ '/awesome/main.scss' ];
+ return [ '/awesome/main.scss' ];
}
public function getTemplateData(): array {
- return [ 'thing_id' => $this->thing->id,
- 'thing_name' => $this->thing->name,
- 'stuff' => $this->stuff ];
+ return [ 'thing_id' => $this->thing->id,
+ 'thing_name' => $this->thing->name,
+ 'stuff' => $this->stuff ];
}
}</code></pre>
</section>
@@ -261,9 +261,9 @@ <h1 style="text-align:center;">Static Analysis</h1>
<pre><code class="shell nohighlight" data-trim style="font-size:1em;" >$ composer require --dev phan/phan</code></pre>
<p class="p" style="font-size:1.5em;text-align:left;">Create .phan/config.php</p>
<pre><code class="shell nohighlight" data-trim style="font-size:1em;" >return [
- 'target_php_version' => '8.0',
- 'directory_list' => [ 'src/' ],
- "exclude_analysis_directory_list" => [ 'vendor/' ],
+ 'target_php_version' => '8.0',
+ 'directory_list' => [ 'src/' ],
+ "exclude_analysis_directory_list" => [ 'vendor/' ],
];</code></pre>
<pre><code class="shell nohighlight" data-trim style="font-size:1em;" >$ ./vendor/bin/phan</code></pre>
</section>
@@ -283,7 +283,7 @@ <h1 style="text-align:center;">Static Analysis</h1>
<pre><code class="shell nohighlight" data-trim style="font-size:1em;" >$ phan --daemonize-tcp-port default &
[1] 28610
Listening for Phan analysis requests at tcp://127.0.0.1:4846
-Awaiting analysis requests for directory '/home/rasmus/phan_demo'
+Awaiting analysis requests for directory '/home/rasmus/phan_demo'
$ vi src/script.php</code></pre>
<pre><code class="shell nohighlight" data-trim style="font-size:1em;" >$ phan_client -l src/script.php
@@ -311,7 +311,7 @@ <h1 style="text-align:center;">phpspy</h1>
</section>
<section id="spy1" >
<p class="p" style="font-size:1.1em;text-align:left;">Sample frequency in nanoseconds (or Hz)</p>
- <pre><code class="shell nohighlight" data-trim style="font-size:0.9em;" >$ phpspy -s 200000000 -- php -r 'sleep(1);'
+ <pre><code class="shell nohighlight" data-trim style="font-size:0.9em;" >$ phpspy -s 200000000 -- php -r 'sleep(1);'
0 sleep <internal>:-1
1 <main> <internal>:-1
@@ -497,9 +497,9 @@ <h1 style="text-align:center;">PHP 8.0</h1>
$leap = !$leap|!($leap%4)&!!($leap%100); // 👀
return match(is_string($month) ? strtolower(substr($month, 0, 3)) : $month) {
- 'apr', 4, 'jun', 6, 'sep', 9, 'nov', 11 => 30,
- 'jan', 1, 'mar', 3, 'may', 5, 'jul', 7, 'aug', 8, 'oct', 10, 'dec', 12 => 31,
- 'feb', 2 => $leap ? 29 : 28,
+ 'apr', 4, 'jun', 6, 'sep', 9, 'nov', 11 => 30,
+ 'jan', 1, 'mar', 3, 'may', 5, 'jul', 7, 'aug', 8, 'oct', 10, 'dec', 12 => 31,
+ 'feb', 2 => $leap ? 29 : 28,
default => throw new InvalidArgumentException("Invalid month"),
};
}</code></pre>
@@ -540,9 +540,11 @@ <h1 style="text-align:center;">PHP 8.1</h1>
function pick_a_card(Suit $suit) { ... }
pick_a_card(Suit::Clubs); // ok
-pick_a_card('Spades'); // error</code></pre>
+pick_a_card('Spades'); // error</code></pre>
</section>
<section id="php81_fibers" >
+ <p class="p" style="font-size:1.1em;text-align:left;">Fibers</p>
+ <p class="p" style="font-size:0.9em;text-align:left;">Full-stack interruptable functions</p>
<pre><code class="php" data-trim style="font-size:1em;" >use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
@@ -556,7 +558,9 @@ <h1 style="text-align:center;">PHP 8.1</h1>
return Fiber::suspend();
}</code></pre>
</section>
- <section id="php81_fibers" >
+ <section id="php81_static_var_inh" >
+ <p class="p" style="font-size:1.1em;text-align:left;">Change: Static Variable Inheritance</p>
+ <p class="p" style="font-size:0.9em;text-align:left;">Inherited method shares parent's static vars</p>
<pre><code class="php" data-trim style="font-size:1em;" >class A {
public static function counter() {
static $i = 0;
@@ -573,15 +577,17 @@ <h1 style="text-align:center;">PHP 8.1</h1>
// PHP 8.1 outputs 1234</code></pre>
</section>
<section id="php81_never" >
+ <p class="p" style="font-size:1.1em;text-align:left;">No Return type</p>
<pre><code class="php" data-trim style="font-size:1em;" >function redirect(string $uri): never {
- header('Location: ' . $uri);
+ header('Location: ' . $uri);
exit();
}
-redirect('/index.html');
+redirect('/index.html');
echo "this will never be executed!";</code></pre>
</section>
<section id="php81_final" >
+ <p class="p" style="font-size:1.1em;text-align:left;">final for class constants</p>
<pre><code class="php" data-trim style="font-size:1em;" >class Foo {
final public const X = "foo";
}
@@ -593,6 +599,7 @@ <h1 style="text-align:center;">PHP 8.1</h1>
// Fatal error: Bar::X cannot override final constant Foo::X</code></pre>
</section>
<section id="php81_new_init" >
+ <p class="p" style="font-size:1.1em;text-align:left;">new expressions can be used in initializers</p>
<pre><code class="php" data-trim style="font-size:1em;" >class Test {
public function __construct(private Logger $logger = new NullLogger) {}
}
@@ -608,17 +615,19 @@ <h1 style="text-align:center;">PHP 8.1</h1>
}</code></pre>
</section>
<section id="php81_first_class_callable" >
+ <p class="p" style="font-size:1.1em;text-align:left;">new expressions can be used in initializers</p>
<pre><code class="php" data-trim style="font-size:1em;" >$fn = strlen(...);
$fn = $this->method(...)
$fn = Foo::method(...);
// instead of
-$fn = Closure::fromCallable('strlen');
-$fn = Closure::fromCallable([$this, 'method']);
-$fn = Closure::fromCallable([Foo::class, 'method']);</code></pre>
+$fn = Closure::fromCallable('strlen');
+$fn = Closure::fromCallable([$this, 'method']);
+$fn = Closure::fromCallable([Foo::class, 'method']);</code></pre>
</section>
<section id="php81_pure_intersection" >
+ <p class="p" style="font-size:1.1em;text-align:left;">Intersection types</p>
<pre><code class="php" data-trim style="font-size:1em;" >class A {
private Traversable&Countable $countableIterator;
@@ -692,7 +701,7 @@ <h1 style="text-align:center;">PHP 8.2</h1>
: new Random\Engine\PCG64(1234);
$randomizer = new Random\Randomizer($rng);
-$randomizer->shuffleString('Testing');</code></pre>
+$randomizer->shuffleString('Testing');</code></pre>
<p class="p" style="font-size:0.75em;text-align:left;">Provides multiple RNG engines as opposed to just using Mersenne Twister</p>
</section>
<section id="php82_trait_constants" >
@@ -718,7 +727,7 @@ <h1 style="text-align:center;">PHP 8.2</h1>
throw new \Exception("Error");
}
}
-$u = new User('rasmus', 'very-secret');</code></pre>
+$u = new User('rasmus', 'very-secret');</code></pre>
<pre class="output" style="font-size:0.4em;">Fatal error: Uncaught Exception
Stack trace:
#0 /home/rasmus/c(7): User->__construct('rasmus', Object(SensitiveParameterValue))
@@ -734,13 +743,13 @@ <h1 style="text-align:center;">PHP 8.2</h1>
class User2 { }
$user = new User();
-$user->last_name = 'Doe'; // Deprecated notice
+$user->last_name = 'Doe'; // Deprecated notice
$user = new User2();
-$user->last_name = 'Doe'; // ok
+$user->last_name = 'Doe'; // ok
$user = new stdClass();
-$user->last_name = 'Doe'; // ok</code></pre>
+$user->last_name = 'Doe'; // ok</code></pre>
</section>
<section id="php82_bite" >
<p class="p" style="font-size:2em;">¡Aguas!</p>
@@ -837,7 +846,7 @@ <h2 style="text-align:center;">Foreign Function Interface</h2>
static function __callStatic(string $function, array $args) {
self::init();
- return self::$cpu->{'cpuinfo_'.$function}(...$args);
+ return self::$cpu->{'cpuinfo_'.$function}(...$args);
}
}</code></pre>
</section>
@@ -853,14 +862,14 @@ <h2 style="text-align:center;">Foreign Function Interface</h2>
static function __callStatic(string $function, array $args) {
self::init();
- $ret = self::$cpu->{'cpufreq_'.$function}(...$args);
+ $ret = self::$cpu->{'cpufreq_'.$function}(...$args);
if ($ret instanceof FFI\CData) {
switch (FFI::typeof($ret)->getName()) {
- case 'char*': $ret = FFI::string($ret); break;
- case 'struct cpufreq_policy*':
- $ret = [ 'min' => $ret->min,
- 'max' => $ret->max,
- 'gov' => FFI::string($ret->governor) ];
+ case 'char*': $ret = FFI::string($ret); break;
+ case 'struct cpufreq_policy*':
+ $ret = [ 'min' => $ret->min,
+ 'max' => $ret->max,
+ 'gov' => FFI::string($ret->governor) ];
break;
}
}
@@ -879,9 +888,9 @@ <h2 style="text-align:center;">Foreign Function Interface</h2>
while(CPUFreq::cpu_exists($cpu) == 0) {
$driver = CPUFreq::get_driver($cpu);
$policy = CPUFreq::get_policy($cpu);
- $governor = $policy['gov'];
- $min = sprintf("%.2f", $policy['min']/1000);
- $max = sprintf("%.2f", $policy['max']/1000);
+ $governor = $policy['gov'];
+ $min = sprintf("%.2f", $policy['min']/1000);
+ $max = sprintf("%.2f", $policy['max']/1000);
echo "CPU " . sprintf("%02d", $cpu) .
" $driver $governor ($min MHz - $max MHz): " .
sprintf("%.2f", CPUFreq::get_freq_kernel($cpu)/1000) . " MHz\n";
diff --git a/slides/intro/php81_2021.xml b/slides/intro/php81_2021.xml
index f54b7262..f0729fbb 100644
--- a/slides/intro/php81_2021.xml
+++ b/slides/intro/php81_2021.xml
@@ -34,6 +34,8 @@ pick_a_card('Spades'); // error
]]></example>
<break lines="1" section="php81_fibers"/>
+<blurb fontsize="1.1em" align="left">Fibers</blurb>
+<blurb fontsize="0.9em" align="left">Full-stack interruptable functions</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
@@ -49,7 +51,9 @@ function await(PromiseInterface $promise, LoopInterface $loop): mixed {
}
]]></example>
-<break lines="1" section="php81_fibers"/>
+<break lines="1" section="php81_static_var_inh"/>
+<blurb fontsize="1.1em" align="left">Change: Static Variable Inheritance</blurb>
+<blurb fontsize="0.9em" align="left">Inherited method shares parent's static vars</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
class A {
public static function counter() {
@@ -68,6 +72,7 @@ echo B::counter();
]]></example>
<break lines="1" section="php81_never"/>
+<blurb fontsize="1.1em" align="left">No Return type</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
function redirect(string $uri): never {
header('Location: ' . $uri);
@@ -79,6 +84,7 @@ echo "this will never be executed!";
]]></example>
<break lines="1" section="php81_final"/>
+<blurb fontsize="1.1em" align="left">final for class constants</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
class Foo {
final public const X = "foo";
@@ -92,6 +98,7 @@ class Bar extends Foo {
]]></example>
<break lines="1" section="php81_new_init"/>
+<blurb fontsize="1.1em" align="left">new expressions can be used in initializers</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
class Test {
public function __construct(private Logger $logger = new NullLogger) {}
@@ -109,6 +116,7 @@ class Test {
]]></example>
<break lines="1" section="php81_first_class_callable"/>
+<blurb fontsize="1.1em" align="left">new expressions can be used in initializers</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
$fn = strlen(...);
$fn = $this->method(...)
@@ -122,6 +130,7 @@ $fn = Closure::fromCallable([Foo::class, 'method']);
]]></example>
<break lines="1" section="php81_pure_intersection"/>
+<blurb fontsize="1.1em" align="left">Intersection types</blurb>
<example fontsize="1em" result='0' title="" type="php"><![CDATA[<?php
class A {
private Traversable&Countable $countableIterator;