@brisphp1
https://brisphp.com
#BrisPHP
Giveaway: brisphp.com/pizza
@brisphp1
https://brisphp.com
#BrisPHP
Types MUST be an ORed series of ANDs.
// Accepts an object that implements C,
// OR one that implements BOTH X AND D,
// OR null.
C|(X&D)|null
// INVALID
// Must be rewritten as (A&B)|(A&D)
A&(B|D)
// INVALID
// Must be rewritten as A|(B&D)|(B&W)|null
A|(B&(D|W)|null)
// Order is irrelevant
// These are all equivalent
(A&B)|(C&D)|(Y&D)|null
(B&A)|null|(D&Y)|(C&D)
null|(C&D)|(B&A)|(Y&D)
@brisphp1
https://brisphp.com
#BrisPHP
enum E: string {
case Foo = 'foo';
}
const C = E::Foo->name;
#[Attr(E::Foo->name)]
class C {}
function f(
$p = E::Foo->value,
) {}
class C {
public string $p = E::Foo->name;
}
@brisphp1
https://brisphp.com
#BrisPHP
trait FooTrait {
public function doFoo(int $value): void {
if ($value > self::MAX_VALUE) {
throw new \Exception('out of range');
}
}
}
class FooClass {
private const MAX_VALUE = 42;
use FooTrait;
}
@brisphp1
https://brisphp.com
#BrisPHP
trait FooTrait {
private const MAX_VALUE = 42;
public function doFoo(int $value): void {
if ($value > self::MAX_VALUE) {
throw new \Exception('out of range');
}
}
}
class FooClass {
private const MAX_VALUE = 42;
use FooTrait;
}
echo FooClass::MAX_VALUE;
// Fatal error
echo Foo::MAX_VALUE;
@brisphp1
https://brisphp.com
#BrisPHP
@brisphp1
https://brisphp.com
#BrisPHP
// Old way
function isJson($string) {
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
}
// New way
var_dump(json_validate('{ "test": { "foo": "bar" } }'));
// true
var_dump(json_validate('{ "": "": "" } }'));
// false
@brisphp1
https://brisphp.com
#BrisPHP