What's new in PHP land? 2022.3

@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)

PHP 8.2 Disjunctive Normal Form Types

@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;
}

PHP 8.2 Fetch enum properties in constant

@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;
}

PHP 8.2 Constants in traits

@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;

PHP 8.2 Constants in traits

@brisphp1

https://brisphp.com

#BrisPHP

PHP 8.2 Release Schedule

@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


PHP 8.3 json_validate

Questions?

@brisphp1

https://brisphp.com

#BrisPHP

Observability Panel

  • Justin Hennessy
  • Ben Plunkett
  • Damian Maclennan

What's new in PHP land - 2022.3

By Nathan Dench

What's new in PHP land - 2022.3

  • 163